@@ -35,7 +35,87 @@ def setup_tmp_local(tmp_path: Path):
3535 yield [local_root , local_empty_root ]
3636
3737
38- @pytest .fixture (scope = "function" , autouse = True )
38+ @pytest .fixture (scope = "function" )
39+ def no_config_permission (tmp_path : Path ):
40+ config_dir = tmp_path / "config"
41+ config_dir .mkdir (exist_ok = True )
42+ os .chmod (config_dir , 0o44 )
43+
44+ with patch (
45+ "jupyter_fsspec.file_manager.jupyter_config_dir" , return_value = str (config_dir )
46+ ):
47+ print (f"Patching jupyter_config_dir to: { config_dir } " )
48+ yield config_dir
49+
50+ os .chmod (config_dir , 0o755 )
51+ config_dir .rmdir ()
52+
53+
54+ @pytest .fixture (scope = "function" )
55+ def malformed_config (tmp_path : Path ):
56+ config_dir = tmp_path / "config"
57+ config_dir .mkdir (exist_ok = True )
58+
59+ yaml_content = f"""sources:
60+ - name: "TestSourceAWS"
61+ path: "s3://my-test-bucket/"
62+ kwargs:
63+ anon: false
64+ key: "my-access-key"
65+ secret: "my-secret-key"
66+ client_kwargs:
67+ endpoint_url: "{ ENDPOINT_URI } "
68+ """
69+ yaml_file = config_dir / "jupyter-fsspec.yaml"
70+ yaml_file .write_text (yaml_content )
71+
72+ with patch (
73+ "jupyter_fsspec.file_manager.jupyter_config_dir" , return_value = str (config_dir )
74+ ):
75+ print (f"Patching jupyter_config_dir to: { config_dir } " )
76+
77+
78+ @pytest .fixture (scope = "function" )
79+ def bad_info_config (tmp_path : Path ):
80+ config_dir = tmp_path / "config"
81+ config_dir .mkdir (exist_ok = True )
82+
83+ yaml_content = f"""sources:
84+ - nme: "TestSourceAWS"
85+ path: s3://my-test-bucket/"
86+ kwargs:
87+ anon: false
88+ key: "my-access-key"
89+ secret: "my-secret-key"
90+ client_kwargs:
91+ endpoint_url: "{ ENDPOINT_URI } "
92+ """
93+ yaml_file = config_dir / "jupyter-fsspec.yaml"
94+ yaml_file .write_text (yaml_content )
95+
96+ with patch (
97+ "jupyter_fsspec.file_manager.jupyter_config_dir" , return_value = str (config_dir )
98+ ):
99+ print (f"Patching jupyter_config_dir to: { config_dir } " )
100+
101+
102+ @pytest .fixture (scope = "function" )
103+ def empty_config (tmp_path : Path ):
104+ config_dir = tmp_path / "config"
105+ config_dir .mkdir (exist_ok = True )
106+
107+ yaml_content = """ """
108+ yaml_file = config_dir / "jupyter-fsspec.yaml"
109+ yaml_file .write_text (yaml_content )
110+
111+ with patch (
112+ "jupyter_fsspec.file_manager.jupyter_config_dir" , return_value = str (config_dir )
113+ ):
114+ print (f"Patching jupyter_config_dir to: { config_dir } " )
115+
116+
117+ # TODO: split?
118+ @pytest .fixture (scope = "function" )
39119def setup_config_file_fs (tmp_path : Path , setup_tmp_local ):
40120 tmp_local = setup_tmp_local [0 ]
41121 items_tmp_local = list (tmp_local .iterdir ())
@@ -76,36 +156,27 @@ def setup_config_file_fs(tmp_path: Path, setup_tmp_local):
76156
77157
78158@pytest .fixture (scope = "function" )
79- def fs_manager_instance (setup_config_file_fs , s3_client ):
159+ async def fs_manager_instance (setup_config_file_fs , s3_client ):
80160 fs_manager = setup_config_file_fs
81161 fs_info = fs_manager .get_filesystem_by_protocol ("memory" )
82162 mem_fs = fs_info ["info" ]["instance" ]
83163 mem_root_path = fs_info ["info" ]["path" ]
84164
85165 if mem_fs :
86- if mem_fs .exists (f"{ mem_root_path } /test_dir" ):
87- mem_fs .rm (f"{ mem_root_path } /test_dir" , recursive = True )
88- if mem_fs .exists (f"{ mem_root_path } /second_dir" ):
89- mem_fs .rm (f"{ mem_root_path } /second_dir" , recursive = True )
90-
91- mem_fs .touch (f"{ mem_root_path } /file_in_root.txt" )
92- with mem_fs .open (f"{ mem_root_path } /file_in_root.txt" , "wb" ) as f :
93- f .write ("Root file content" .encode ())
94-
95- mem_fs .mkdir (f"{ mem_root_path } /test_dir" , exist_ok = True )
96- mem_fs .mkdir (f"{ mem_root_path } /second_dir" , exist_ok = True )
97- # mem_fs.mkdir(f'{mem_root_path}/second_dir/subdir', exist_ok=True)
98- mem_fs .touch (f"{ mem_root_path } /test_dir/file1.txt" )
99- with mem_fs .open (f"{ mem_root_path } /test_dir/file1.txt" , "wb" ) as f :
100- f .write ("Test content" .encode ())
101- f .close ()
166+ if await mem_fs ._exists (f"{ mem_root_path } /test_dir" ):
167+ await mem_fs ._rm (f"{ mem_root_path } /test_dir" , recursive = True )
168+ if await mem_fs ._exists (f"{ mem_root_path } /second_dir" ):
169+ await mem_fs ._rm (f"{ mem_root_path } /second_dir" , recursive = True )
170+
171+ await mem_fs ._pipe (f"{ mem_root_path } /file_in_root.txt" , b"Root file content" )
172+
173+ await mem_fs ._mkdir (f"{ mem_root_path } /test_dir" , exist_ok = True )
174+ await mem_fs ._mkdir (f"{ mem_root_path } /second_dir" , exist_ok = True )
175+
176+ await mem_fs ._pipe (f"{ mem_root_path } /test_dir/file1.txt" , b"Test content" )
102177 else :
103178 print ("In memory filesystem NOT FOUND" )
104179
105- if mem_fs .exists (f"{ mem_root_path } /test_dir/file1.txt" ):
106- mem_fs .info (f"{ mem_root_path } /test_dir/file1.txt" )
107- else :
108- print ("File does not exist!" )
109180 return fs_manager
110181
111182
0 commit comments