def test_initialize(self): """ Checks if the initialization has grouped the right checks under each file. """ qajson_checks = [QajsonCheck.from_dict(d) for d in self.checks_json] checkrunner = CheckRunner(qajson_checks) checkrunner.initialize() file_one_checks = checkrunner._file_checks[('test/one.all', 'Raw Files')] # make sure the right checks have been grouped under each file fn_check = next( (x for x in file_one_checks if x.info.id == "7761e08b-1380-46fa-a7eb-f1f41db38541"), None) dc_check = next( (x for x in file_one_checks if x.info.id == "4a3f3371-3a21-44f2-93cf-d9ed19d0c002"), None) self.assertEqual(len(file_one_checks), 2) self.assertIsNotNone(fn_check) self.assertIsNotNone(dc_check) file_two_checks = checkrunner._file_checks[('test/two.all', 'Raw Files')] self.assertEqual(len(file_two_checks), 1) file_three_checks = checkrunner._file_checks[('test/three.all', 'Raw Files')] self.assertEqual(len(file_three_checks), 1)
def update_qa_json_input_files(self, qa_json: QajsonRoot, files: List[Path]) -> NoReturn: """ Updates qa_json to support the list of provided files. function defined in base class has been overwritten to support some MBES GC specifics in the way it supports multiple files. """ # when this function has been called qa_json has been updated to # include the list of checks. While Mate will support processing of # multiple files within one QA JSON check definition, the QA JSON # schema doesn't support multiple outputs per check. To work around # this, this function take the specified checks, and adds one check # definition per file. Each Mate check is therefore run with a single # input file, but the same check is duplicated for each file passed in all_data_levels = [check_ref.data_level for check_ref in self.checks()] all_data_levels = list(set(all_data_levels)) # build a list of GC checks in the qa_json for all the different data # levels (this really only needs to check the raw_data data level) all_mgc_checks = [] for dl in all_data_levels: dl_sp = getattr(qa_json.qa, dl) if dl_sp is None: continue for check in dl_sp.checks: if self.get_check_reference(check.info.id) is not None: all_mgc_checks.append(check) # now remove the current mgc definitions as we'll add these all back # in again for each input file. for mgc_check in all_mgc_checks: for dl in all_data_levels: dl_sp = getattr(qa_json.qa, dl) dl_sp.checks.remove(mgc_check) for (input_file, input_file_group) in files: for mgc_check in all_mgc_checks: check_ref = self.get_check_reference(mgc_check.info.id) if not check_ref.supports_file(input_file, input_file_group): continue mgc_check_clone = QajsonCheck.from_dict(mgc_check.to_dict()) inputs = mgc_check_clone.get_or_add_inputs() inputs.files.append( QajsonFile(path=str(input_file), file_type=input_file_group, description=None)) # ** ASSUME ** mgc checks only go in the survey_products # data level qa_json.qa.survey_products.checks.append(mgc_check_clone)
def qajson_from_inputs( input: InputFileDetails, check_classes: List[Type['GridCheck']]) -> QajsonRoot: checks = [] for check_class in check_classes: info = QajsonInfo( id=check_class.id, name=check_class.name, description=None, version=check_class.version, group=QajsonGroup("", "", ""), ) input_file_path, _, _ = input.input_band_details[0] input_file = QajsonFile( path=input_file_path, file_type="Survey DTMs", description=None ) inputs = QajsonInputs( files=[input_file], params=check_class.input_params ) check = QajsonCheck( info=info, inputs=inputs, outputs=None ) checks.append(check) datalevel = QajsonDataLevel(checks=checks) qa = QajsonQa( version=latest_schema_version(), raw_data=QajsonDataLevel([]), survey_products=datalevel, chart_adequacy=None ) root = QajsonRoot(qa) return root
def _get_or_add_check(self, data_level: QajsonDataLevel, check_reference: QaxCheckReference) -> QajsonCheck: """ If a check exists it will be returned, otherwise a new check will be created, added, and then returned. """ matching_check = data_level.get_check(check_reference.id) if matching_check is not None: return matching_check check_info = QajsonInfo( id=check_reference.id, name=check_reference.name, description=check_reference.description, version=check_reference.version, group=QajsonGroup("", "", ""), ) new_check = QajsonCheck(info=check_info, inputs=None, outputs=None) data_level.checks.append(new_check) return new_check