-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_base.py
144 lines (127 loc) · 3.96 KB
/
test_base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import subprocess
from typing import Any
from tests.utils import (
assert_files_exist,
assert_html_contains,
run_build,
run_build_with_custom_input,
)
# The output can be seen manually by running the following command:
# poetry run mkslides build tests/test_files
def test_process_directory_without_config(setup_paths: Any) -> None:
cwd, output_path = setup_paths
run_build(cwd, output_path)
assert_files_exist(
output_path,
[
"assets/reveal-js/dist/reveal.css",
"assets/reveal-js/dist/reveal.js",
"assets/reveal-js/plugin/markdown/markdown.js",
"assets/reveal-js/plugin/highlight/highlight.js",
"assets/reveal-js/plugin/zoom/zoom.js",
"assets/black.css",
"assets/monokai.css",
"index.html",
"someslides.html",
"somefolder/someslides.html",
"img/example-1.png",
"img/example-2.png",
"img/example-3.png",
"img/example-4.png",
"img/example-(7).png",
"img/somefolder/example-5.png",
"somefolder/example-6.png",
"test-1.txt",
"test-2.txt",
"test-(3).txt",
"video/demo.webm",
],
)
assert_html_contains(
output_path / "someslides.html",
[
'<link rel="stylesheet" href="assets/reveal-js/dist/reveal.css" />',
'<link rel="stylesheet" href="assets/black.css" />',
'<link rel="stylesheet" href="assets/monokai.css" />',
],
)
assert_html_contains(
output_path / "somefolder/someslides.html",
[
'<link rel="stylesheet" href="../assets/reveal-js/dist/reveal.css" />',
'<link rel="stylesheet" href="../assets/black.css" />',
'<link rel="stylesheet" href="../assets/monokai.css" />',
],
)
def test_prevent_overwrite(setup_paths: Any) -> None:
cwd, output_path = setup_paths
file1_path = output_path / "test" / "test.md"
file1_path.parent.mkdir(parents=True, exist_ok=True)
file1_path.write_text("# Test 1")
file2_path = output_path / "test" / "test2" / "test2.md"
file2_path.parent.mkdir(parents=True, exist_ok=True)
file2_path.write_text("# Test 2")
result = subprocess.run(
[
"mkslides",
"-v",
"build",
"-d",
output_path,
file1_path.parent,
],
cwd=cwd,
capture_output=True,
text=True,
check=False,
)
assert result.returncode == 1
result = subprocess.run(
[
"mkslides",
"-v",
"build",
"-d",
output_path,
file2_path.parent,
],
cwd=cwd,
capture_output=True,
text=True,
check=False,
)
assert result.returncode == 1
assert_files_exist(
output_path,
[
"test/test.md",
"test/test2/test2.md",
],
)
def test_process_file_without_config(setup_paths: Any) -> None:
cwd, output_path = setup_paths
run_build_with_custom_input(cwd, output_path, "test_files/someslides.md")
assert_files_exist(
output_path,
[
"assets/reveal-js/dist/reveal.css",
"assets/reveal-js/dist/reveal.js",
"assets/reveal-js/plugin/markdown/markdown.js",
"assets/reveal-js/plugin/highlight/highlight.js",
"assets/reveal-js/plugin/zoom/zoom.js",
"assets/black.css",
"assets/monokai.css",
"index.html",
"img/example-1.png",
"img/example-2.png",
"img/example-3.png",
"img/example-(7).png",
"test-1.txt",
"test-2.txt",
"test-(3).txt",
"video/demo.webm",
],
)
assert not (
output_path / "someslides.html"
).exists(), "someslides.html should not exist"