diff --git a/sohstationviewer/controller/processing.py b/sohstationviewer/controller/processing.py index 34da617fed44d4d248d0854a2698c043da0e8ead..cbdb5f442ba5da4feff8410b1d1fe9e2f9aac1f1 100644 --- a/sohstationviewer/controller/processing.py +++ b/sohstationviewer/controller/processing.py @@ -169,9 +169,10 @@ def detect_data_type(list_of_dir: List[str]) -> Optional[str]: sign_chan_data_type_dict = get_signature_channels() dir_data_type_dict = {} - is_multiplex = None + is_multiplex_dict = {} for d in list_of_dir: data_type = "Unknown" + is_multiplex = None for path, subdirs, files in os.walk(d): for file_name in files: path2file = Path(path).joinpath(file_name) @@ -191,10 +192,12 @@ def detect_data_type(list_of_dir: List[str]) -> Optional[str]: if is_multiplex is None: raise Exception("No channel found for the data set") + is_multiplex_dict[d] = is_multiplex if data_type == "Unknown": dir_data_type_dict[d] = "Unknown" else: dir_data_type_dict[d] = data_type + is_multiplex_list = list(set(is_multiplex_dict.values())) data_type_list = list(set(dir_data_type_dict.values())) if len(data_type_list) > 1: dir_data_type_str = json.dumps(dir_data_type_dict) @@ -204,13 +207,17 @@ def detect_data_type(list_of_dir: List[str]) -> Optional[str]: f"{dir_data_type_str}\n\n" f"Please have only data that related to each other.") raise Exception(msg) - + elif len(is_multiplex_list) > 1: + msg = ("There are both multiplexed and non-multiplexed data " + "detected.\n\nPlease have only data that related to" + " each other.") + raise Exception(msg) elif data_type_list == ['Unknown']: msg = ("There are no known data detected.\n\n" "Do you want to cancel to select different folder(s)\n" "Or continue to read any available mseed file?") raise Exception(msg) - return data_type_list[0], is_multiplex + return data_type_list[0], is_multiplex_list[0] def get_data_type_from_file( diff --git a/tests/controller/test_processing.py b/tests/controller/test_processing.py index fb377d015d60633f8ab05c3ae8051c7f98d4dbd9..b6e411b827c2828512b3036df7f482937007ad4d 100644 --- a/tests/controller/test_processing.py +++ b/tests/controller/test_processing.py @@ -256,6 +256,22 @@ class TestDetectDataType(TestCase): f"{self.dir2.name}: Q330\n\n" f"Please have only data that related to each other.") + def test_same_data_types_different_multiplex(self): + """ + Test basic functionality of detect_data_type - the given directories + contain same data types but different multiplex. + """ + returned_data_types = [('Q330', True), ('Q330', False)] + self.mock_get_data_type_from_file.side_effect = returned_data_types + + with self.assertRaises(Exception) as context: + detect_data_type([self.dir1.name, self.dir2.name]) + self.assertEqual( + str(context.exception), + "There are both multiplexed and non-multiplexed data " + "detected.\n\nPlease have only data that related to" + " each other.") + def test_unknown_data_type(self): """ Test basic functionality of detect_data_type - can't detect any data