Skip to content

Commit e2d6f8f

Browse files
uncomment
1 parent d4af147 commit e2d6f8f

File tree

1 file changed

+118
-118
lines changed

1 file changed

+118
-118
lines changed

tests/test_pytest_plugin.py

Lines changed: 118 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -15,176 +15,176 @@
1515
NB_VERSION = 4
1616

1717

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"))
2323

2424

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")
2727

28-
# items, hook_recorder = pytester.inline_genitems("--nbmake")
28+
items, hook_recorder = pytester.inline_genitems("--nbmake")
2929

30-
# assert hook_recorder.ret == ExitCode.OK
31-
# assert len(items) == 1
30+
assert hook_recorder.ret == ExitCode.OK
31+
assert len(items) == 1
3232

3333

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")
3636

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+
)
4040

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
4343

4444

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")
4949

50-
# items, hook_recorder = pytester.inline_genitems("--nbmake")
50+
items, hook_recorder = pytester.inline_genitems("--nbmake")
5151

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
5454

5555

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)]
5858

59-
# hook_recorder = pytester.inline_run("--nbmake", "-n=auto")
59+
hook_recorder = pytester.inline_run("--nbmake", "-n=auto")
6060

61-
# assert hook_recorder.ret == ExitCode.OK
61+
assert hook_recorder.ret == ExitCode.OK
6262

6363

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]
7373

74-
# hook_recorder = pytester.inline_run("--nbmake", "-vvv")
74+
hook_recorder = pytester.inline_run("--nbmake", "-vvv")
7575

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 == []
8181

82-
# assert hook_recorder.ret == ExitCode.OK
82+
assert hook_recorder.ret == ExitCode.OK
8383

8484

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]
9191

92-
# hook_recorder = pytester.inline_run("--nbmake", "--overwrite")
92+
hook_recorder = pytester.inline_run("--nbmake", "--overwrite")
9393

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 != []
9999

100-
# assert hook_recorder.ret == ExitCode.OK
100+
assert hook_recorder.ret == ExitCode.OK
101101

102102

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")
111111

112-
# [write_nb(passing_nb, path) for path in nbs]
112+
[write_nb(passing_nb, path) for path in nbs]
113113

114-
# hook_recorder = pytester.inline_run("--nbmake", "-vvv")
114+
hook_recorder = pytester.inline_run("--nbmake", "-vvv")
115115

116-
# assert hook_recorder.ret == ExitCode.OK
116+
assert hook_recorder.ret == ExitCode.OK
117117

118118

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")
121121

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
124124

125125

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")
128128

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()
132132

133133

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("")
139139

140-
# hook_recorder = pytester.inline_run("--nbmake")
140+
hook_recorder = pytester.inline_run("--nbmake")
141141

142-
# assert hook_recorder.ret == ExitCode.OK
142+
assert hook_recorder.ret == ExitCode.OK
143143

144144

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")
149149

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
152152

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
155155

156156

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+
)
167167

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
170170

171171

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+
)
184184

185-
# hook_recorder = pytester.inline_run("--nbmake", "--nbmake-kernel=python3")
185+
hook_recorder = pytester.inline_run("--nbmake", "--nbmake-kernel=python3")
186186

187-
# assert hook_recorder.ret == ExitCode.OK
187+
assert hook_recorder.ret == ExitCode.OK
188188

189189

190190
def test_when_no_import_errs_then_pass(pytester: Pytester, testdir2: Never):

0 commit comments

Comments
 (0)