def test_json_import_user_invalid(self): expected_error_message = 'Metadata are corrupted; the file cannot be imported' test_file = './test/unit/test_data/user_invalid.json' systemInfo_populated = copy.deepcopy(systemInfo_mockup) systemInfo_populated['courses']['test_course']['users'] = {} with self.assertRaisesRegex(ImportException, expected_error_message): import_export.import_data(systemInfo_populated, test_file)
def test_json_import_session_valid(self): test_file = './test/unit/test_data/session_valid.json' systemInfo_populated = copy.deepcopy(systemInfo_mockup) systemInfo_populated['courses']['test_course']['users']['test_user'][ 'sessions'] = {} result = import_export.import_data(systemInfo_populated, test_file) self.assertDictEqual(result, systemInfo_mockup)
def import_and_reduce(raw_data_folder_path, file_name, t_min, t_max, q_thres): raw_data = import_data( raw_data_folder_path, file_name ) #Import data from folderpath + filename, format is a vector, each element a datpoint raw_data_int = convert_to_int(raw_data) #Convert values in vector to int reduced_raw_data_int = filter_data( raw_data_int, t_min, t_max, q_thres ) #Remove datapoint with to large or low t, and datapoint with too low q_thres return reduced_raw_data_int
def import_data(self, filename: str, overwrite: bool = False): """Import the whole system or a part of it Args: filename (str): the filename (filepath) that we are importing; overwrite (bool): if the imported information is already present in the system and overwrite = False then a message is returned and the file is not imported. Defaults to False. Returns: A message containing the import status; Done if sucessful """ try: self._systemInfo = import_export.import_data( self._systemInfo, filename, overwrite) except ImportException as exc: pass return 'Done'
def test_json_import_course_malformed(self): expected_error_message = 'Some layers above the level you are inserting are not present in the system' test_file = './test/unit/test_data/course_valid.json' malformed_systemInfo = {} with self.assertRaisesRegex(ImportException, expected_error_message): import_export.import_data(malformed_systemInfo, test_file)
def test_json_import_course_invalid(self): expected_error_message = 'Metadata are corrupted; the file cannot be imported' test_file = './test/unit/test_data/course_invalid.json' with self.assertRaisesRegex(ImportException, expected_error_message): import_export.import_data(self.test_systemInfo, test_file)
def test_json_import_system_valid(self): test_file = './test/unit/test_data/system_valid.json' result = import_export.import_data(self.test_systemInfo, test_file) self.assertDictEqual(result, systemInfo_mockup)
def test_json_import_corrupted_metadata(self): expected_error_message = 'The file is corrupted and does not contain the appropriate metadata' test_file = './test/unit/test_data/corrupted_metadata.json' with self.assertRaisesRegex(ImportException, expected_error_message): import_export.import_data(self.test_systemInfo, test_file)
def test_import_file_format_not_supported(self): expected_error_message = 'File format not supported' with self.assertRaisesRegex(ImportException, expected_error_message): import_export.import_data(self.test_systemInfo, 'not_supported.xml')
def test_import_file_not_found(self): expected_error_message = 'File not found: unknown.json' with self.assertRaisesRegex(ImportException, expected_error_message): import_export.import_data(self.test_systemInfo, 'unknown.json')
def test_json_import_lower_level_with_overwrite_issue(self): expected_error_message = 'Import has overwrite conflict; try to launch with overwrite = True' test_file = './test/unit/test_data/course_valid.json' systemInfo_populated = copy.deepcopy(systemInfo_mockup) with self.assertRaisesRegex(ImportException, expected_error_message): import_export.import_data(systemInfo_populated, test_file)
def test_json_import_system_with_overwrite_issue(self): expected_error_message = 'Trying to overwrite the whole system without permissions; try overwrite = True' test_file = './test/unit/test_data/system_valid.json' systemInfo_populated = copy.deepcopy(systemInfo_mockup) with self.assertRaisesRegex(ImportException, expected_error_message): import_export.import_data(systemInfo_populated, test_file)