Skip to content

Commit cad571f

Browse files
committed
Tidy up testing file
1 parent 1235707 commit cad571f

File tree

1 file changed

+32
-52
lines changed

1 file changed

+32
-52
lines changed

tests/cli_test.py

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,28 @@
66

77
from runbook import cli
88

9+
python_template = "./runbooks/binder/_template-python.ipynb"
10+
deno_template = "./runbooks/binder/_template-deno.ipynb"
11+
new_template = "./runbooks/binder/new-template.ipynb"
12+
13+
base_paths = [
14+
"./runbooks",
15+
"./runbooks/binder",
16+
"./runbooks/runs",
17+
"./runbooks/.runbook.json",
18+
python_template,
19+
deno_template,
20+
]
21+
922

1023
def invoker(runner, argv, working_dir, prog_name="runbook"):
1124
return runner.invoke(
12-
cli, argv, env={"RUNBOOK_WORKING_DIR": working_dir}, prog_name=prog_name
25+
cli,
26+
argv,
27+
env={
28+
"RUNBOOK_WORKING_DIR": working_dir,
29+
},
30+
prog_name=prog_name,
1331
)
1432

1533

@@ -48,15 +66,7 @@ def test_cli_init():
4866
with runner.isolated_filesystem() as dir:
4967
result = invoker(runner, ["init"], dir)
5068
assert result.exit_code == 0
51-
paths = [
52-
"./runbooks",
53-
"./runbooks/binder",
54-
"./runbooks/runs",
55-
"./runbooks/.runbook.json",
56-
"./runbooks/binder/_template-python.ipynb",
57-
"./runbooks/binder/_template-deno.ipynb",
58-
]
59-
for p in paths:
69+
for p in base_paths:
6070
assert Path(p).exists()
6171

6272

@@ -66,29 +76,21 @@ def test_cli_create():
6676
result = invoker(runner, ["init"], dir)
6777
result = invoker(runner, ["create", "new-template"], dir)
6878
assert result.exit_code == 0
69-
paths = [
70-
"./runbooks",
71-
"./runbooks/binder",
72-
"./runbooks/runs",
73-
"./runbooks/.runbook.json",
74-
"./runbooks/binder/_template-python.ipynb",
75-
"./runbooks/binder/_template-deno.ipynb",
76-
"./runbooks/binder/new-template.ipynb",
77-
]
79+
paths = [*base_paths, new_template]
7880
for p in paths:
7981
assert Path(p).exists()
8082

81-
with open("./runbooks/binder/_template-python.ipynb", encoding="utf8") as f:
83+
with open(python_template, encoding="utf8") as f:
8284
nb = nbformat.read(f, 4)
8385
c = nb.cells[2]
8486
assert "parameters" in c.metadata.tags
8587

86-
with open("./runbooks/binder/_template-deno.ipynb", encoding="utf8") as f:
88+
with open(deno_template, encoding="utf8") as f:
8789
nb = nbformat.read(f, 4)
8890
c = nb.cells[2]
8991
assert "parameters" in c.metadata.tags
9092

91-
with open("./runbooks/binder/new-template.ipynb", encoding="utf8") as f:
93+
with open(new_template, encoding="utf8") as f:
9294
nb = nbformat.read(f, 4)
9395
c = nb.cells[2]
9496
assert "parameters" in c.metadata.tags
@@ -101,29 +103,21 @@ def test_cli_lifecycle_to_plan():
101103
assert result.exit_code == 0
102104
result = invoker(runner, ["create", "new-template"], dir)
103105
assert result.exit_code == 0
104-
paths = [
105-
"./runbooks",
106-
"./runbooks/binder",
107-
"./runbooks/runs",
108-
"./runbooks/.runbook.json",
109-
"./runbooks/binder/_template-python.ipynb",
110-
"./runbooks/binder/_template-deno.ipynb",
111-
"./runbooks/binder/new-template.ipynb",
112-
]
106+
paths = [*base_paths, new_template]
113107
for p in paths:
114108
assert Path(p).exists()
115109

116-
with open("./runbooks/binder/_template-python.ipynb", encoding="utf8") as f:
110+
with open(python_template, encoding="utf8") as f:
117111
nb = nbformat.read(f, 4)
118112
c = nb.cells[2]
119113
assert "parameters" in c.metadata.tags
120114

121-
with open("./runbooks/binder/_template-deno.ipynb", encoding="utf8") as f:
115+
with open(deno_template, encoding="utf8") as f:
122116
nb = nbformat.read(f, 4)
123117
c = nb.cells[2]
124118
assert "parameters" in c.metadata.tags
125119

126-
with open("./runbooks/binder/new-template.ipynb", encoding="utf8") as f:
120+
with open(new_template, encoding="utf8") as f:
127121
nb = nbformat.read(f, 4)
128122
c = nb.cells[2]
129123
assert "parameters" in c.metadata.tags
@@ -149,34 +143,20 @@ def test_cli_lifecycle_to_run():
149143
assert result.exit_code == 0
150144
result = invoker(runner, ["create", "new-template"], dir)
151145
assert result.exit_code == 0
152-
paths = [
153-
"./runbooks",
154-
"./runbooks/binder",
155-
"./runbooks/runs",
156-
"./runbooks/.runbook.json",
157-
"./runbooks/binder/_template-python.ipynb",
158-
"./runbooks/binder/_template-deno.ipynb",
159-
"./runbooks/binder/new-template.ipynb",
160-
]
146+
paths = [*base_paths, new_template]
161147
for p in paths:
162148
assert Path(p).exists()
163149

164-
with open("./runbooks/binder/_template-python.ipynb", encoding="utf8") as f:
150+
with open(python_template, encoding="utf8") as f:
165151
nb = nbformat.read(f, 4)
166152
c = nb.cells[2]
167153
assert "parameters" in c.metadata.tags
168154

169-
with open("./runbooks/binder/_template-deno.ipynb", encoding="utf8") as f:
155+
with open(deno_template, encoding="utf8") as f:
170156
nb = nbformat.read(f, 4)
171157
c = nb.cells[2]
172158
assert "parameters" in c.metadata.tags
173159

174-
# TODO: fix tags being not present for parameters despite being there in _template
175-
# with open("./runbooks/binder/new-template.ipynb", encoding="utf8") as f:
176-
# nb = nbformat.read(f, 4)
177-
# c = nb.cells[2]
178-
# assert "parameters" in c.metadata.tags
179-
180160
# TODO: fix multiple singletons of ServerApp
181-
# result = invoker(runner, ["run", "./runbooks/binder/new-template.ipynb"], dir)
161+
# result = invoker(runner, ["run", deno_template], dir)
182162
# assert result.exit_code == 0

0 commit comments

Comments
 (0)