@@ -80,15 +80,15 @@ def test_file_protocol(self):
80
80
self .assertEqual (None , zarr_dir .storage_options )
81
81
self .assertIsInstance (zarr_dir .fs , fsspec .AbstractFileSystem )
82
82
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 )
84
84
85
85
def test_local_protocol (self ):
86
86
zarr_dir = FileObj ("test.zarr" )
87
87
self .assertEqual ("test.zarr" , zarr_dir .uri )
88
88
self .assertEqual (None , zarr_dir .storage_options )
89
89
self .assertIsInstance (zarr_dir .fs , fsspec .AbstractFileSystem )
90
90
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 )
92
92
93
93
def test_s3_protocol (self ):
94
94
zarr_dir = FileObj ("s3://eo-data/test.zarr" )
@@ -131,7 +131,7 @@ def test_truediv_override(self):
131
131
"eo-data/test.zarr/chl/.zarray" ,
132
132
)
133
133
134
- def test_parent (self ):
134
+ def test_parent_with_uri (self ):
135
135
file = FileObj ("s3://eo-data/test.zarr/.zmetadata" )
136
136
fs = file .fs
137
137
@@ -157,15 +157,26 @@ def test_parent(self):
157
157
# noinspection PyUnusedLocal
158
158
parent = parent .parent
159
159
160
+ def test_parent_with_local (self ):
160
161
# local filesystem
161
162
file = FileObj ("test.zarr/chl/.zarray" )
162
163
fs = file .fs
163
164
parent = file .parent
164
165
self .assertIsInstance (parent , FileObj )
165
166
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 )
169
180
self .assertIs (fs , parent .fs )
170
181
171
182
def test_parent_with_chained_uri (self ):
@@ -183,12 +194,10 @@ def test_parent_with_chained_uri(self):
183
194
parent = file .parent
184
195
self .assertIsInstance (parent , FileObj )
185
196
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 )
189
198
self .assertIs (fs , parent .fs )
190
199
191
- def test_for_path (self ):
200
+ def test_for_path_with_simple_uri (self ):
192
201
root = FileObj ("s3://eo-data/test.zarr" )
193
202
194
203
derived = root .for_path ("" )
@@ -208,6 +217,11 @@ def test_for_path_with_chained_uri(self):
208
217
root , derived , "dir://chl/.zarray::file:/eo-data/test.zarr" , "chl/.zarray"
209
218
)
210
219
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
+
211
225
def assert_derived_ok (
212
226
self , root : FileObj , derived : FileObj , expected_uri : str , expected_path : str
213
227
):
@@ -217,13 +231,13 @@ def assert_derived_ok(
217
231
self .assertIs (root .storage_options , derived .storage_options )
218
232
219
233
# noinspection PyMethodMayBeStatic
220
- def test_for_path_with_abs_path (self ):
234
+ def test_raises_for_path_with_abs_path (self ):
221
235
fo = FileObj ("file:/eo-data/test.zarr" )
222
236
with pytest .raises (ValueError , match = "rel_path must be relative" ):
223
237
fo .for_path ("/test-2.zarr" )
224
238
225
239
# noinspection PyMethodMayBeStatic
226
- def test_for_path_with_wrong_type (self ):
240
+ def test_raises_for_path_with_wrong_type (self ):
227
241
fo = FileObj ("file:/eo-data/test.zarr" )
228
242
with pytest .raises (TypeError , match = "rel_path must have type str" ):
229
243
# noinspection PyTypeChecker
@@ -282,3 +296,7 @@ def to_protocol(fs: fsspec.AbstractFileSystem):
282
296
if isinstance (fs .protocol , tuple ):
283
297
return fs .protocol [0 ]
284
298
return fs .protocol
299
+
300
+
301
+ def to_abs (path : str ) -> str :
302
+ return os .path .abspath (path ).replace ("\\ " , "/" )
0 commit comments