1
1
import pytest
2
2
import tornado
3
3
4
+ from jupyter_server .services .contents .largefilemanager import AsyncLargeFileManager , LargeFileManager
5
+ from jupyter_server .utils import ensure_async
4
6
from ...utils import expected_http_error
5
7
6
8
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 ):
8
17
cm = jp_large_contents_manager
9
- model = cm .new_untitled (type = 'notebook' )
18
+ model = await ensure_async ( cm .new_untitled (type = 'notebook' ) )
10
19
name = model ['name' ]
11
20
path = model ['path' ]
12
21
13
22
# Get the model with 'content'
14
- full_model = cm .get (path )
23
+ full_model = await ensure_async ( cm .get (path ) )
15
24
# Save the notebook
16
- model = cm .save (full_model , path )
25
+ model = await ensure_async ( cm .save (full_model , path ) )
17
26
assert isinstance (model , dict )
18
27
assert 'name' in model
19
28
assert 'path' in model
@@ -43,26 +52,26 @@ def test_save(jp_large_contents_manager):
43
52
)
44
53
]
45
54
)
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 ):
47
56
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' ]) )
49
58
assert expected_http_error (e , 400 , expected_message = err_message )
50
59
51
60
52
- def test_saving_different_chunks (jp_large_contents_manager ):
61
+ async def test_saving_different_chunks (jp_large_contents_manager ):
53
62
cm = jp_large_contents_manager
54
63
model = {'name' : 'test' , 'path' : 'test' , 'type' : 'file' ,
55
64
'content' : u'test==' , 'format' : 'text' }
56
65
name = model ['name' ]
57
66
path = model ['path' ]
58
- cm .save (model , path )
67
+ await ensure_async ( cm .save (model , path ) )
59
68
60
69
for chunk in (1 , 2 , - 1 ):
61
70
for fm in ('text' , 'base64' ):
62
- full_model = cm .get (path )
71
+ full_model = await ensure_async ( cm .get (path ) )
63
72
full_model ['chunk' ] = chunk
64
73
full_model ['format' ] = fm
65
- model_res = cm .save (full_model , path )
74
+ model_res = await ensure_async ( cm .save (full_model , path ) )
66
75
assert isinstance (model_res , dict )
67
76
assert 'name' in model_res
68
77
assert 'path' in model_res
@@ -71,16 +80,16 @@ def test_saving_different_chunks(jp_large_contents_manager):
71
80
assert model_res ['path' ] == path
72
81
73
82
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 ):
75
84
cm = jp_large_contents_manager
76
85
sub_dir = tmp_path / 'foo'
77
86
sub_dir .mkdir ()
78
- model = cm .new_untitled (path = '/foo/' , type = 'notebook' )
87
+ model = await ensure_async ( cm .new_untitled (path = '/foo/' , type = 'notebook' ) )
79
88
path = model ['path' ]
80
- model = cm .get (path )
89
+ model = await ensure_async ( cm .get (path ) )
81
90
82
91
# Change the name in the model for rename
83
- model = cm .save (model , path )
92
+ model = await ensure_async ( cm .save (model , path ) )
84
93
assert isinstance (model , dict )
85
94
assert 'name' in model
86
95
assert 'path' in model
0 commit comments