|
15 | 15 | NB_VERSION = 4
|
16 | 16 |
|
17 | 17 |
|
18 |
| -# def test_import(): |
19 |
| -# reload(import_module("nbmake.nb_result")) |
20 |
| -# reload(import_module("nbmake.nb_run")) |
21 |
| -# reload(import_module("nbmake.pytest_plugin")) |
22 |
| -# reload(import_module("nbmake.pytest_items")) |
| 18 | +def test_import(): |
| 19 | + reload(import_module("nbmake.nb_result")) |
| 20 | + reload(import_module("nbmake.nb_run")) |
| 21 | + reload(import_module("nbmake.pytest_plugin")) |
| 22 | + reload(import_module("nbmake.pytest_items")) |
23 | 23 |
|
24 | 24 |
|
25 |
| -# def test_when_nb_present_then_collected(pytester: Pytester, testdir2: Never): |
26 |
| -# write_nb(passing_nb, Path(pytester.path) / "a.ipynb") |
| 25 | +def test_when_nb_present_then_collected(pytester: Pytester, testdir2: Never): |
| 26 | + write_nb(passing_nb, Path(pytester.path) / "a.ipynb") |
27 | 27 |
|
28 |
| -# items, hook_recorder = pytester.inline_genitems("--nbmake") |
| 28 | + items, hook_recorder = pytester.inline_genitems("--nbmake") |
29 | 29 |
|
30 |
| -# assert hook_recorder.ret == ExitCode.OK |
31 |
| -# assert len(items) == 1 |
| 30 | + assert hook_recorder.ret == ExitCode.OK |
| 31 | + assert len(items) == 1 |
32 | 32 |
|
33 | 33 |
|
34 |
| -# def test_when_ignored_none_collected(pytester: Pytester, testdir2: Never): |
35 |
| -# write_nb(passing_nb, Path(pytester.path) / "a.ipynb") |
| 34 | +def test_when_ignored_none_collected(pytester: Pytester, testdir2: Never): |
| 35 | + write_nb(passing_nb, Path(pytester.path) / "a.ipynb") |
36 | 36 |
|
37 |
| -# items, hook_recorder = pytester.inline_genitems( |
38 |
| -# "--nbmake", "--ignore-glob", "*.ipynb" |
39 |
| -# ) |
| 37 | + items, hook_recorder = pytester.inline_genitems( |
| 38 | + "--nbmake", "--ignore-glob", "*.ipynb" |
| 39 | + ) |
40 | 40 |
|
41 |
| -# assert hook_recorder.ret == ExitCode.NO_TESTS_COLLECTED |
42 |
| -# assert len(items) == 0 |
| 41 | + assert hook_recorder.ret == ExitCode.NO_TESTS_COLLECTED |
| 42 | + assert len(items) == 0 |
43 | 43 |
|
44 | 44 |
|
45 |
| -# def test_when_in_build_dir_none_collected(pytester: Pytester, testdir2: Never): |
46 |
| -# build_dir = Path("_build") |
47 |
| -# build_dir.mkdir() |
48 |
| -# write_nb(passing_nb, build_dir / "a.ipynb") |
| 45 | +def test_when_in_build_dir_none_collected(pytester: Pytester, testdir2: Never): |
| 46 | + build_dir = Path("_build") |
| 47 | + build_dir.mkdir() |
| 48 | + write_nb(passing_nb, build_dir / "a.ipynb") |
49 | 49 |
|
50 |
| -# items, hook_recorder = pytester.inline_genitems("--nbmake") |
| 50 | + items, hook_recorder = pytester.inline_genitems("--nbmake") |
51 | 51 |
|
52 |
| -# assert hook_recorder.ret == ExitCode.NO_TESTS_COLLECTED |
53 |
| -# assert len(items) == 0 |
| 52 | + assert hook_recorder.ret == ExitCode.NO_TESTS_COLLECTED |
| 53 | + assert len(items) == 0 |
54 | 54 |
|
55 | 55 |
|
56 |
| -# def test_when_parallel_passing_nbs_then_ok(pytester: Pytester, testdir2: Never): |
57 |
| -# [write_nb(passing_nb, Path(f"{i}.ipynb")) for i in range(20)] |
| 56 | +def test_when_parallel_passing_nbs_then_ok(pytester: Pytester, testdir2: Never): |
| 57 | + [write_nb(passing_nb, Path(f"{i}.ipynb")) for i in range(20)] |
58 | 58 |
|
59 |
| -# hook_recorder = pytester.inline_run("--nbmake", "-n=auto") |
| 59 | + hook_recorder = pytester.inline_run("--nbmake", "-n=auto") |
60 | 60 |
|
61 |
| -# assert hook_recorder.ret == ExitCode.OK |
| 61 | + assert hook_recorder.ret == ExitCode.OK |
62 | 62 |
|
63 | 63 |
|
64 |
| -# def test_when_passing_nbs_then_ok(pytester: Pytester, testdir2: Never): |
65 |
| -# nbs = [ |
66 |
| -# Path(pytester.path) / "a.ipynb", |
67 |
| -# Path(pytester.path) / "b nb.ipynb", |
68 |
| -# Path(pytester.path) / Path("sub dir/a.ipynb"), |
69 |
| -# Path(pytester.path) / Path("sub dir/b.ipynb"), |
70 |
| -# ] |
71 |
| -# pytester.mkdir("sub dir") |
72 |
| -# [write_nb(passing_nb, path) for path in nbs] |
| 64 | +def test_when_passing_nbs_then_ok(pytester: Pytester, testdir2: Never): |
| 65 | + nbs = [ |
| 66 | + Path(pytester.path) / "a.ipynb", |
| 67 | + Path(pytester.path) / "b nb.ipynb", |
| 68 | + Path(pytester.path) / Path("sub dir/a.ipynb"), |
| 69 | + Path(pytester.path) / Path("sub dir/b.ipynb"), |
| 70 | + ] |
| 71 | + pytester.mkdir("sub dir") |
| 72 | + [write_nb(passing_nb, path) for path in nbs] |
73 | 73 |
|
74 |
| -# hook_recorder = pytester.inline_run("--nbmake", "-vvv") |
| 74 | + hook_recorder = pytester.inline_run("--nbmake", "-vvv") |
75 | 75 |
|
76 |
| -# for path in nbs: |
77 |
| -# nb = read(str(path), NB_VERSION) |
78 |
| -# for cell in nb.cells: |
79 |
| -# if "outputs" in cell: |
80 |
| -# assert cell.outputs == [] |
| 76 | + for path in nbs: |
| 77 | + nb = read(str(path), NB_VERSION) |
| 78 | + for cell in nb.cells: |
| 79 | + if "outputs" in cell: |
| 80 | + assert cell.outputs == [] |
81 | 81 |
|
82 |
| -# assert hook_recorder.ret == ExitCode.OK |
| 82 | + assert hook_recorder.ret == ExitCode.OK |
83 | 83 |
|
84 | 84 |
|
85 |
| -# def test_when_overwrite_then_overwritten(pytester: Pytester, testdir2: Never): |
86 |
| -# nbs = [ |
87 |
| -# Path(pytester.path) / Path("sub dir/b.ipynb"), |
88 |
| -# ] |
89 |
| -# pytester.mkdir("sub dir") |
90 |
| -# [write_nb(["1+1"], path) for path in nbs] |
| 85 | +def test_when_overwrite_then_overwritten(pytester: Pytester, testdir2: Never): |
| 86 | + nbs = [ |
| 87 | + Path(pytester.path) / Path("sub dir/b.ipynb"), |
| 88 | + ] |
| 89 | + pytester.mkdir("sub dir") |
| 90 | + [write_nb(["1+1"], path) for path in nbs] |
91 | 91 |
|
92 |
| -# hook_recorder = pytester.inline_run("--nbmake", "--overwrite") |
| 92 | + hook_recorder = pytester.inline_run("--nbmake", "--overwrite") |
93 | 93 |
|
94 |
| -# for path in nbs: |
95 |
| -# nb = read(str(path), NB_VERSION) |
96 |
| -# for cell in nb.cells: |
97 |
| -# if "outputs" in cell: |
98 |
| -# assert cell.outputs != [] |
| 94 | + for path in nbs: |
| 95 | + nb = read(str(path), NB_VERSION) |
| 96 | + for cell in nb.cells: |
| 97 | + if "outputs" in cell: |
| 98 | + assert cell.outputs != [] |
99 | 99 |
|
100 |
| -# assert hook_recorder.ret == ExitCode.OK |
| 100 | + assert hook_recorder.ret == ExitCode.OK |
101 | 101 |
|
102 | 102 |
|
103 |
| -# def test_when_run_from_non_root_then_ok(pytester: Pytester, testdir2: Never): |
104 |
| -# os.environ["PATH"] += f"/home/vscode:{os.environ['PATH']}" |
105 |
| -# nbs = [ |
106 |
| -# Path(pytester.path) / Path("sub dir/b.ipynb"), |
107 |
| -# ] |
108 |
| -# pytester.mkdir("sub dir") |
109 |
| -# Path("pytest.ini").write_text("") |
110 |
| -# os.chdir("sub dir") |
| 103 | +def test_when_run_from_non_root_then_ok(pytester: Pytester, testdir2: Never): |
| 104 | + os.environ["PATH"] += f"/home/vscode:{os.environ['PATH']}" |
| 105 | + nbs = [ |
| 106 | + Path(pytester.path) / Path("sub dir/b.ipynb"), |
| 107 | + ] |
| 108 | + pytester.mkdir("sub dir") |
| 109 | + Path("pytest.ini").write_text("") |
| 110 | + os.chdir("sub dir") |
111 | 111 |
|
112 |
| -# [write_nb(passing_nb, path) for path in nbs] |
| 112 | + [write_nb(passing_nb, path) for path in nbs] |
113 | 113 |
|
114 |
| -# hook_recorder = pytester.inline_run("--nbmake", "-vvv") |
| 114 | + hook_recorder = pytester.inline_run("--nbmake", "-vvv") |
115 | 115 |
|
116 |
| -# assert hook_recorder.ret == ExitCode.OK |
| 116 | + assert hook_recorder.ret == ExitCode.OK |
117 | 117 |
|
118 | 118 |
|
119 |
| -# def test_when_failing_nb_then_fail(pytester: Pytester, testdir2: Never): |
120 |
| -# write_nb(failing_nb, Path(pytester.path) / "a.ipynb") |
| 119 | +def test_when_failing_nb_then_fail(pytester: Pytester, testdir2: Never): |
| 120 | + write_nb(failing_nb, Path(pytester.path) / "a.ipynb") |
121 | 121 |
|
122 |
| -# hook_recorder = pytester.inline_run("--nbmake", "-v") |
123 |
| -# assert hook_recorder.ret == ExitCode.TESTS_FAILED |
| 122 | + hook_recorder = pytester.inline_run("--nbmake", "-v") |
| 123 | + assert hook_recorder.ret == ExitCode.TESTS_FAILED |
124 | 124 |
|
125 | 125 |
|
126 |
| -# def test_when_no_html_flag_then_no_build_dir(pytester: Pytester, testdir2: Never): |
127 |
| -# write_nb(failing_nb, Path(pytester.path) / "a.ipynb") |
| 126 | +def test_when_no_html_flag_then_no_build_dir(pytester: Pytester, testdir2: Never): |
| 127 | + write_nb(failing_nb, Path(pytester.path) / "a.ipynb") |
128 | 128 |
|
129 |
| -# hook_recorder = pytester.inline_run("--nbmake") |
130 |
| -# assert hook_recorder.ret == ExitCode.TESTS_FAILED |
131 |
| -# assert not Path("_build").exists() |
| 129 | + hook_recorder = pytester.inline_run("--nbmake") |
| 130 | + assert hook_recorder.ret == ExitCode.TESTS_FAILED |
| 131 | + assert not Path("_build").exists() |
132 | 132 |
|
133 | 133 |
|
134 |
| -# def test_when_init_then_passes(pytester: Pytester, testdir2: Never): |
135 |
| -# example_dir = Path(pytester.path) / "example" |
136 |
| -# example_dir.mkdir() |
137 |
| -# write_nb(passing_nb, example_dir / "a.ipynb") |
138 |
| -# (example_dir / "__init__.py").write_text("") |
| 134 | +def test_when_init_then_passes(pytester: Pytester, testdir2: Never): |
| 135 | + example_dir = Path(pytester.path) / "example" |
| 136 | + example_dir.mkdir() |
| 137 | + write_nb(passing_nb, example_dir / "a.ipynb") |
| 138 | + (example_dir / "__init__.py").write_text("") |
139 | 139 |
|
140 |
| -# hook_recorder = pytester.inline_run("--nbmake") |
| 140 | + hook_recorder = pytester.inline_run("--nbmake") |
141 | 141 |
|
142 |
| -# assert hook_recorder.ret == ExitCode.OK |
| 142 | + assert hook_recorder.ret == ExitCode.OK |
143 | 143 |
|
144 | 144 |
|
145 |
| -# def test_when_timeout_flag_then_uses_as_default(pytester: Pytester, testdir2: Never): |
146 |
| -# example_dir = Path(pytester.path) / "example" |
147 |
| -# example_dir.mkdir() |
148 |
| -# write_nb(["import time; time.sleep(2)"], example_dir / "a.ipynb") |
| 145 | +def test_when_timeout_flag_then_uses_as_default(pytester: Pytester, testdir2: Never): |
| 146 | + example_dir = Path(pytester.path) / "example" |
| 147 | + example_dir.mkdir() |
| 148 | + write_nb(["import time; time.sleep(2)"], example_dir / "a.ipynb") |
149 | 149 |
|
150 |
| -# hook_recorder = pytester.inline_run("--nbmake", "--nbmake-timeout=3") |
151 |
| -# assert hook_recorder.ret == ExitCode.OK |
| 150 | + hook_recorder = pytester.inline_run("--nbmake", "--nbmake-timeout=3") |
| 151 | + assert hook_recorder.ret == ExitCode.OK |
152 | 152 |
|
153 |
| -# hook_recorder = pytester.inline_run("--nbmake", "--nbmake-timeout=1") |
154 |
| -# assert hook_recorder.ret == ExitCode.TESTS_FAILED |
| 153 | + hook_recorder = pytester.inline_run("--nbmake", "--nbmake-timeout=1") |
| 154 | + assert hook_recorder.ret == ExitCode.TESTS_FAILED |
155 | 155 |
|
156 | 156 |
|
157 |
| -# def test_when_explicit_metadata_then_ignore_timeout( |
158 |
| -# pytester: Pytester, testdir2: Never |
159 |
| -# ): |
160 |
| -# example_dir = Path(pytester.path) / "example" |
161 |
| -# example_dir.mkdir() |
162 |
| -# write_nb( |
163 |
| -# ["import time; time.sleep(2)"], |
164 |
| -# example_dir / "a.ipynb", |
165 |
| -# metadata={"execution": {"timeout": 10}}, |
166 |
| -# ) |
| 157 | +def test_when_explicit_metadata_then_ignore_timeout( |
| 158 | + pytester: Pytester, testdir2: Never |
| 159 | +): |
| 160 | + example_dir = Path(pytester.path) / "example" |
| 161 | + example_dir.mkdir() |
| 162 | + write_nb( |
| 163 | + ["import time; time.sleep(2)"], |
| 164 | + example_dir / "a.ipynb", |
| 165 | + metadata={"execution": {"timeout": 10}}, |
| 166 | + ) |
167 | 167 |
|
168 |
| -# hook_recorder = pytester.inline_run("--nbmake", "--nbmake-timeout=1") |
169 |
| -# assert hook_recorder.ret == ExitCode.OK |
| 168 | + hook_recorder = pytester.inline_run("--nbmake", "--nbmake-timeout=1") |
| 169 | + assert hook_recorder.ret == ExitCode.OK |
170 | 170 |
|
171 | 171 |
|
172 |
| -# def test_when_kernel_passed_then_override(pytester: Pytester, testdir2: Never): |
173 |
| -# write_nb( |
174 |
| -# passing_nb, |
175 |
| -# Path(f"x.ipynb"), |
176 |
| -# metadata={ |
177 |
| -# "kernelspec": { |
178 |
| -# "display_name": "Python 3", |
179 |
| -# "language": "python", |
180 |
| -# "name": "blah", |
181 |
| -# } |
182 |
| -# }, |
183 |
| -# ) |
| 172 | +def test_when_kernel_passed_then_override(pytester: Pytester, testdir2: Never): |
| 173 | + write_nb( |
| 174 | + passing_nb, |
| 175 | + Path(f"x.ipynb"), |
| 176 | + metadata={ |
| 177 | + "kernelspec": { |
| 178 | + "display_name": "Python 3", |
| 179 | + "language": "python", |
| 180 | + "name": "blah", |
| 181 | + } |
| 182 | + }, |
| 183 | + ) |
184 | 184 |
|
185 |
| -# hook_recorder = pytester.inline_run("--nbmake", "--nbmake-kernel=python3") |
| 185 | + hook_recorder = pytester.inline_run("--nbmake", "--nbmake-kernel=python3") |
186 | 186 |
|
187 |
| -# assert hook_recorder.ret == ExitCode.OK |
| 187 | + assert hook_recorder.ret == ExitCode.OK |
188 | 188 |
|
189 | 189 |
|
190 | 190 | def test_when_no_import_errs_then_pass(pytester: Pytester, testdir2: Never):
|
|
0 commit comments