16
16
from jupyter_server .serverapp import ServerApp
17
17
from jupyter_server .utils import url_path_join
18
18
19
+ import nbformat
20
+
19
21
20
22
pytest_plugins = "pytest_tornasync"
21
23
@@ -184,7 +186,6 @@ def base_url(http_server_port):
184
186
@pytest .fixture
185
187
def fetch (http_server_client , auth_header , base_url ):
186
188
"""fetch fixture that handles auth, base_url, and path"""
187
-
188
189
def client_fetch (* parts , headers = {}, params = {}, ** kwargs ):
189
190
# Handle URL strings
190
191
path_url = url_escape (url_path_join (base_url , * parts ), plus = False )
@@ -196,5 +197,22 @@ def client_fetch(*parts, headers={}, params={}, **kwargs):
196
197
return http_server_client .fetch (
197
198
url , headers = headers , request_timeout = 20 , ** kwargs
198
199
)
200
+ return client_fetch
199
201
200
- return client_fetch
202
+
203
+ @pytest .fixture
204
+ def create_notebook (root_dir ):
205
+ """Create a notebook in the test's home directory."""
206
+ def inner (nbpath ):
207
+ nbpath = root_dir .joinpath (nbpath )
208
+ # Check that the notebook has the correct file extension.
209
+ if nbpath .suffix != '.ipynb' :
210
+ raise Exception ("File extension for notebook must be .ipynb" )
211
+ # If the notebook path has a parent directory, make sure it's created.
212
+ parent = nbpath .parent
213
+ parent .mkdir (parents = True , exist_ok = True )
214
+ # Create a notebook string and write to file.
215
+ nb = nbformat .v4 .new_notebook ()
216
+ nbtext = nbformat .writes (nb , version = 4 )
217
+ nbpath .write_text (nbtext )
218
+ return inner
0 commit comments