2525# noinspection PyUnusedLocal
2626
2727
28- # noinspection PyShadowingBuiltins,PyRedeclaration
28+ # noinspection PyShadowingBuiltins,PyRedeclaration,PyMethodMayBeStatic
2929class OpenSliceDatasetTest (unittest .TestCase ):
3030 def setUp (self ):
3131 clear_memory_fs ()
@@ -35,6 +35,7 @@ def test_slice_item_is_slice_source(self):
3535 ctx = Context (dict (target_dir = "memory://target.zarr" ))
3636 slice_item = MemorySliceSource (dataset , 0 )
3737 slice_cm = open_slice_dataset (ctx , slice_item )
38+ self .assertIsInstance (slice_cm , SliceSourceContextManager )
3839 self .assertIs (slice_item , slice_cm .slice_source )
3940
4041 def test_slice_item_is_dataset (self ):
@@ -163,7 +164,7 @@ def get_dataset(name):
163164 with slice_cm as slice_ds :
164165 self .assertIsInstance (slice_ds , xr .Dataset )
165166
166- def test_slice_item_is_slice_source (self ):
167+ def test_slice_item_is_slice_source_arg (self ):
167168 class MySliceSource (SliceSource ):
168169 def __init__ (self , name ):
169170 self .uri = f"memory://{ name } .zarr"
@@ -190,7 +191,7 @@ def close(self):
190191 with slice_cm as slice_ds :
191192 self .assertIsInstance (slice_ds , xr .Dataset )
192193
193- def test_slice_item_is_deprecated_slice_source (self ):
194+ def test_slice_item_is_deprecated_slice_source_arg (self ):
194195 class MySliceSource (SliceSource ):
195196 def __init__ (self , name ):
196197 self .uri = f"memory://{ name } .zarr"
@@ -218,6 +219,33 @@ def dispose(self):
218219 with slice_cm as slice_ds :
219220 self .assertIsInstance (slice_ds , xr .Dataset )
220221
222+ def test_slice_item_is_slice_source_arg_with_extra_kwargs (self ):
223+ class MySliceSource (SliceSource ):
224+ def __init__ (self , * args , ** kwargs ):
225+ self .args = args
226+ self .kwargs = kwargs
227+
228+ def get_dataset (self ):
229+ return xr .Dataset ()
230+
231+ ctx = Context (
232+ dict (
233+ target_dir = "memory://target.zarr" ,
234+ slice_source = MySliceSource ,
235+ slice_source_kwargs = {"a" : 1 , "b" : True , "c" : "nearest" },
236+ )
237+ )
238+ slice_cm = open_slice_dataset (ctx , (["bibo" ], {"a" : 2 , "d" : 3.14 }))
239+ self .assertIsInstance (slice_cm , SliceSourceContextManager )
240+ slice_source = slice_cm .slice_source
241+ self .assertIsInstance (slice_source , MySliceSource )
242+ with slice_cm as slice_ds :
243+ self .assertIsInstance (slice_ds , xr .Dataset )
244+ self .assertEquals (slice_source .args , ("bibo" ,))
245+ self .assertEquals (
246+ slice_source .kwargs , {"a" : 2 , "b" : True , "c" : "nearest" , "d" : 3.14 }
247+ )
248+
221249
222250class IsContextManagerTest (unittest .TestCase ):
223251 """Assert that context managers are identified by isinstance()"""
0 commit comments