@@ -80,15 +80,15 @@ def test_file_protocol(self):
8080 self .assertEqual (None , zarr_dir .storage_options )
8181 self .assertIsInstance (zarr_dir .fs , fsspec .AbstractFileSystem )
8282 self .assertEqual ("file" , to_protocol (zarr_dir .fs ))
83- self .assertEqual (os . path . abspath ("test.zarr" ). replace ( " \\ " , "/ " ), zarr_dir .path )
83+ self .assertEqual (to_abs ("test.zarr" ), zarr_dir .path )
8484
8585 def test_local_protocol (self ):
8686 zarr_dir = FileObj ("test.zarr" )
8787 self .assertEqual ("test.zarr" , zarr_dir .uri )
8888 self .assertEqual (None , zarr_dir .storage_options )
8989 self .assertIsInstance (zarr_dir .fs , fsspec .AbstractFileSystem )
9090 self .assertEqual ("file" , to_protocol (zarr_dir .fs ))
91- self .assertEqual (os . path . abspath ("test.zarr" ). replace ( " \\ " , "/ " ), zarr_dir .path )
91+ self .assertEqual (to_abs ("test.zarr" ), zarr_dir .path )
9292
9393 def test_s3_protocol (self ):
9494 zarr_dir = FileObj ("s3://eo-data/test.zarr" )
@@ -131,7 +131,7 @@ def test_truediv_override(self):
131131 "eo-data/test.zarr/chl/.zarray" ,
132132 )
133133
134- def test_parent (self ):
134+ def test_parent_with_uri (self ):
135135 file = FileObj ("s3://eo-data/test.zarr/.zmetadata" )
136136 fs = file .fs
137137
@@ -157,15 +157,26 @@ def test_parent(self):
157157 # noinspection PyUnusedLocal
158158 parent = parent .parent
159159
160+ def test_parent_with_local (self ):
160161 # local filesystem
161162 file = FileObj ("test.zarr/chl/.zarray" )
162163 fs = file .fs
163164 parent = file .parent
164165 self .assertIsInstance (parent , FileObj )
165166 self .assertEqual ("test.zarr/chl" , parent .uri )
166- self .assertEqual (
167- os .path .abspath ("test.zarr/chl" ).replace ("\\ " , "/" ), parent .path
168- )
167+ self .assertEqual (to_abs ("test.zarr/chl" ), parent .path )
168+ self .assertIs (fs , parent .fs )
169+
170+ parent = parent .parent
171+ self .assertIsInstance (parent , FileObj )
172+ self .assertEqual ("test.zarr" , parent .uri )
173+ self .assertEqual (to_abs ("test.zarr" ), parent .path )
174+ self .assertIs (fs , parent .fs )
175+
176+ parent = parent .parent
177+ self .assertIsInstance (parent , FileObj )
178+ self .assertEqual ("" , parent .uri )
179+ self .assertEqual (to_abs ("" ), parent .path )
169180 self .assertIs (fs , parent .fs )
170181
171182 def test_parent_with_chained_uri (self ):
@@ -183,12 +194,10 @@ def test_parent_with_chained_uri(self):
183194 parent = file .parent
184195 self .assertIsInstance (parent , FileObj )
185196 self .assertEqual ("test.zarr/chl::/eo-data/test.zarr" , parent .uri )
186- self .assertEqual (
187- os .path .abspath ("test.zarr/chl" ).replace ("\\ " , "/" ), parent .path
188- )
197+ self .assertEqual (to_abs ("test.zarr/chl" ), parent .path )
189198 self .assertIs (fs , parent .fs )
190199
191- def test_for_path (self ):
200+ def test_for_path_with_simple_uri (self ):
192201 root = FileObj ("s3://eo-data/test.zarr" )
193202
194203 derived = root .for_path ("" )
@@ -208,6 +217,11 @@ def test_for_path_with_chained_uri(self):
208217 root , derived , "dir://chl/.zarray::file:/eo-data/test.zarr" , "chl/.zarray"
209218 )
210219
220+ def test_for_path_with_empty_parent (self ):
221+ root = FileObj ("test.zarr" ).parent
222+ derived = root .for_path ("test.zarr" )
223+ self .assert_derived_ok (root , derived , "test.zarr" , to_abs ("test.zarr" ))
224+
211225 def assert_derived_ok (
212226 self , root : FileObj , derived : FileObj , expected_uri : str , expected_path : str
213227 ):
@@ -217,13 +231,13 @@ def assert_derived_ok(
217231 self .assertIs (root .storage_options , derived .storage_options )
218232
219233 # noinspection PyMethodMayBeStatic
220- def test_for_path_with_abs_path (self ):
234+ def test_raises_for_path_with_abs_path (self ):
221235 fo = FileObj ("file:/eo-data/test.zarr" )
222236 with pytest .raises (ValueError , match = "rel_path must be relative" ):
223237 fo .for_path ("/test-2.zarr" )
224238
225239 # noinspection PyMethodMayBeStatic
226- def test_for_path_with_wrong_type (self ):
240+ def test_raises_for_path_with_wrong_type (self ):
227241 fo = FileObj ("file:/eo-data/test.zarr" )
228242 with pytest .raises (TypeError , match = "rel_path must have type str" ):
229243 # noinspection PyTypeChecker
@@ -282,3 +296,7 @@ def to_protocol(fs: fsspec.AbstractFileSystem):
282296 if isinstance (fs .protocol , tuple ):
283297 return fs .protocol [0 ]
284298 return fs .protocol
299+
300+
301+ def to_abs (path : str ) -> str :
302+ return os .path .abspath (path ).replace ("\\ " , "/" )
0 commit comments