6
6
7
7
from runbook import cli
8
8
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
+
9
22
10
23
def invoker (runner , argv , working_dir , prog_name = "runbook" ):
11
24
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 ,
13
31
)
14
32
15
33
@@ -48,15 +66,7 @@ def test_cli_init():
48
66
with runner .isolated_filesystem () as dir :
49
67
result = invoker (runner , ["init" ], dir )
50
68
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 :
60
70
assert Path (p ).exists ()
61
71
62
72
@@ -66,29 +76,21 @@ def test_cli_create():
66
76
result = invoker (runner , ["init" ], dir )
67
77
result = invoker (runner , ["create" , "new-template" ], dir )
68
78
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 ]
78
80
for p in paths :
79
81
assert Path (p ).exists ()
80
82
81
- with open ("./runbooks/binder/_template-python.ipynb" , encoding = "utf8" ) as f :
83
+ with open (python_template , encoding = "utf8" ) as f :
82
84
nb = nbformat .read (f , 4 )
83
85
c = nb .cells [2 ]
84
86
assert "parameters" in c .metadata .tags
85
87
86
- with open ("./runbooks/binder/_template-deno.ipynb" , encoding = "utf8" ) as f :
88
+ with open (deno_template , encoding = "utf8" ) as f :
87
89
nb = nbformat .read (f , 4 )
88
90
c = nb .cells [2 ]
89
91
assert "parameters" in c .metadata .tags
90
92
91
- with open ("./runbooks/binder/new-template.ipynb" , encoding = "utf8" ) as f :
93
+ with open (new_template , encoding = "utf8" ) as f :
92
94
nb = nbformat .read (f , 4 )
93
95
c = nb .cells [2 ]
94
96
assert "parameters" in c .metadata .tags
@@ -101,29 +103,21 @@ def test_cli_lifecycle_to_plan():
101
103
assert result .exit_code == 0
102
104
result = invoker (runner , ["create" , "new-template" ], dir )
103
105
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 ]
113
107
for p in paths :
114
108
assert Path (p ).exists ()
115
109
116
- with open ("./runbooks/binder/_template-python.ipynb" , encoding = "utf8" ) as f :
110
+ with open (python_template , encoding = "utf8" ) as f :
117
111
nb = nbformat .read (f , 4 )
118
112
c = nb .cells [2 ]
119
113
assert "parameters" in c .metadata .tags
120
114
121
- with open ("./runbooks/binder/_template-deno.ipynb" , encoding = "utf8" ) as f :
115
+ with open (deno_template , encoding = "utf8" ) as f :
122
116
nb = nbformat .read (f , 4 )
123
117
c = nb .cells [2 ]
124
118
assert "parameters" in c .metadata .tags
125
119
126
- with open ("./runbooks/binder/new-template.ipynb" , encoding = "utf8" ) as f :
120
+ with open (new_template , encoding = "utf8" ) as f :
127
121
nb = nbformat .read (f , 4 )
128
122
c = nb .cells [2 ]
129
123
assert "parameters" in c .metadata .tags
@@ -149,34 +143,20 @@ def test_cli_lifecycle_to_run():
149
143
assert result .exit_code == 0
150
144
result = invoker (runner , ["create" , "new-template" ], dir )
151
145
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 ]
161
147
for p in paths :
162
148
assert Path (p ).exists ()
163
149
164
- with open ("./runbooks/binder/_template-python.ipynb" , encoding = "utf8" ) as f :
150
+ with open (python_template , encoding = "utf8" ) as f :
165
151
nb = nbformat .read (f , 4 )
166
152
c = nb .cells [2 ]
167
153
assert "parameters" in c .metadata .tags
168
154
169
- with open ("./runbooks/binder/_template-deno.ipynb" , encoding = "utf8" ) as f :
155
+ with open (deno_template , encoding = "utf8" ) as f :
170
156
nb = nbformat .read (f , 4 )
171
157
c = nb .cells [2 ]
172
158
assert "parameters" in c .metadata .tags
173
159
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
-
180
160
# 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)
182
162
# assert result.exit_code == 0
0 commit comments