@@ -113,7 +113,7 @@ def test_open_packed(self):
113113# noinspection PyUnresolvedReferences,PyPep8Naming
114114class FsDataStoresTestMixin (ABC ):
115115 @abstractmethod
116- def create_data_store (self ) -> FsDataStore :
116+ def create_data_store (self , read_only = False ) -> FsDataStore :
117117 pass
118118
119119 @classmethod
@@ -138,6 +138,28 @@ def prepare_fs(cls, fs: fsspec.AbstractFileSystem, root: str):
138138 with fs .open (file_path , "w" ) as fp :
139139 fp .write ("\n " )
140140
141+ def test_no_write_to_read_only (self ):
142+ data_store = self .create_data_store (read_only = True )
143+ data = new_cube_data ()
144+ with self .assertRaises (DataStoreError ) as dse :
145+ data_store .write_data (data )
146+ self .assertEqual ("Data store is read-only." , f"{ dse .exception } " )
147+
148+ def test_no_delete_on_read_only (self ):
149+ data_store = self .create_data_store (read_only = True )
150+ with self .assertRaises (DataStoreError ) as dse :
151+ data_store .delete_data ("the_data_id_does_not_even_matter.nc" )
152+ self .assertEqual ("Data store is read-only." , f"{ dse .exception } " )
153+
154+ def test_cannot_open_unknown_format (self ):
155+ data_store = self .create_data_store ()
156+ with self .assertRaises (DataStoreError ) as dse :
157+ data_store .open_data ("unknown.format" )
158+ self .assertEqual (
159+ "Cannot determine data type for data resource 'unknown.format'" ,
160+ f"{ dse .exception } "
161+ )
162+
141163 def test_mldataset_levels (self ):
142164 data_store = self .create_data_store ()
143165 self ._assert_multi_level_dataset_format_supported (data_store )
@@ -492,21 +514,21 @@ def _assert_dataset_supported(
492514
493515
494516class FileFsDataStoresTest (FsDataStoresTestMixin , unittest .TestCase ):
495- def create_data_store (self ) -> FsDataStore :
517+ def create_data_store (self , read_only = False ) -> FsDataStore :
496518 root = os .path .join (new_temp_dir (prefix = "xcube" ), ROOT_DIR )
497519 self .prepare_fs (fsspec .filesystem ("file" ), root )
498- return new_fs_data_store ("file" , root = root , max_depth = 3 )
520+ return new_fs_data_store ("file" , root = root , max_depth = 3 , read_only = read_only )
499521
500522
501523class MemoryFsDataStoresTest (FsDataStoresTestMixin , unittest .TestCase ):
502- def create_data_store (self ) -> FsDataStore :
524+ def create_data_store (self , read_only = False ) -> FsDataStore :
503525 root = ROOT_DIR
504526 self .prepare_fs (fsspec .filesystem ("memory" ), root )
505- return new_fs_data_store ("memory" , root = root , max_depth = 3 )
527+ return new_fs_data_store ("memory" , root = root , max_depth = 3 , read_only = read_only )
506528
507529
508530class S3FsDataStoresTest (FsDataStoresTestMixin , S3Test ):
509- def create_data_store (self ) -> FsDataStore :
531+ def create_data_store (self , read_only = False ) -> FsDataStore :
510532 root = ROOT_DIR
511533 storage_options = dict (
512534 anon = False ,
@@ -516,7 +538,8 @@ def create_data_store(self) -> FsDataStore:
516538 )
517539 self .prepare_fs (fsspec .filesystem ("s3" , ** storage_options ), root )
518540 return new_fs_data_store (
519- "s3" , root = root , max_depth = 3 , storage_options = storage_options
541+ "s3" , root = root , max_depth = 3 , storage_options = storage_options ,
542+ read_only = read_only
520543 )
521544
522545class GetFilenameExtensionsTest (unittest .TestCase ):
0 commit comments