11import pytest
22import tornado
33
4+ from jupyter_server .services .contents .largefilemanager import AsyncLargeFileManager , LargeFileManager
5+ from jupyter_server .utils import ensure_async
46from ...utils import expected_http_error
57
68
7- def test_save (jp_large_contents_manager ):
9+ @pytest .fixture (params = [LargeFileManager , AsyncLargeFileManager ])
10+ def jp_large_contents_manager (request , tmp_path ):
11+ """Returns a LargeFileManager instance."""
12+ file_manager = request .param
13+ return file_manager (root_dir = str (tmp_path ))
14+
15+
16+ async def test_save (jp_large_contents_manager ):
817 cm = jp_large_contents_manager
9- model = cm .new_untitled (type = 'notebook' )
18+ model = await ensure_async ( cm .new_untitled (type = 'notebook' ) )
1019 name = model ['name' ]
1120 path = model ['path' ]
1221
1322 # Get the model with 'content'
14- full_model = cm .get (path )
23+ full_model = await ensure_async ( cm .get (path ) )
1524 # Save the notebook
16- model = cm .save (full_model , path )
25+ model = await ensure_async ( cm .save (full_model , path ) )
1726 assert isinstance (model , dict )
1827 assert 'name' in model
1928 assert 'path' in model
@@ -43,26 +52,26 @@ def test_save(jp_large_contents_manager):
4352 )
4453 ]
4554)
46- def test_bad_save (jp_large_contents_manager , model , err_message ):
55+ async def test_bad_save (jp_large_contents_manager , model , err_message ):
4756 with pytest .raises (tornado .web .HTTPError ) as e :
48- jp_large_contents_manager .save (model , model ['path' ])
57+ await ensure_async ( jp_large_contents_manager .save (model , model ['path' ]) )
4958 assert expected_http_error (e , 400 , expected_message = err_message )
5059
5160
52- def test_saving_different_chunks (jp_large_contents_manager ):
61+ async def test_saving_different_chunks (jp_large_contents_manager ):
5362 cm = jp_large_contents_manager
5463 model = {'name' : 'test' , 'path' : 'test' , 'type' : 'file' ,
5564 'content' : u'test==' , 'format' : 'text' }
5665 name = model ['name' ]
5766 path = model ['path' ]
58- cm .save (model , path )
67+ await ensure_async ( cm .save (model , path ) )
5968
6069 for chunk in (1 , 2 , - 1 ):
6170 for fm in ('text' , 'base64' ):
62- full_model = cm .get (path )
71+ full_model = await ensure_async ( cm .get (path ) )
6372 full_model ['chunk' ] = chunk
6473 full_model ['format' ] = fm
65- model_res = cm .save (full_model , path )
74+ model_res = await ensure_async ( cm .save (full_model , path ) )
6675 assert isinstance (model_res , dict )
6776 assert 'name' in model_res
6877 assert 'path' in model_res
@@ -71,16 +80,16 @@ def test_saving_different_chunks(jp_large_contents_manager):
7180 assert model_res ['path' ] == path
7281
7382
74- def test_save_in_subdirectory (jp_large_contents_manager , tmp_path ):
83+ async def test_save_in_subdirectory (jp_large_contents_manager , tmp_path ):
7584 cm = jp_large_contents_manager
7685 sub_dir = tmp_path / 'foo'
7786 sub_dir .mkdir ()
78- model = cm .new_untitled (path = '/foo/' , type = 'notebook' )
87+ model = await ensure_async ( cm .new_untitled (path = '/foo/' , type = 'notebook' ) )
7988 path = model ['path' ]
80- model = cm .get (path )
89+ model = await ensure_async ( cm .get (path ) )
8190
8291 # Change the name in the model for rename
83- model = cm .save (model , path )
92+ model = await ensure_async ( cm .save (model , path ) )
8493 assert isinstance (model , dict )
8594 assert 'name' in model
8695 assert 'path' in model
0 commit comments