def setUp(self): super().setUp() self.dimension = Dimension(translations='translations') self.dimension.correct_virtual = 1 self.dimension.correct_reporting = 1 self.dimension.correct_ceiling_virtual = 2 self.dimension.correct_ceiling_reporting = 2 self.dimension.incorrect_virtual = 1 self.dimension.incorrect_reporting = 1 self.dimension_none = Dimension( deserialized_files='deserialized files') self.dimension_none.correct_virtual = 0 self.dimension_none.correct_reporting = 0 self.dimension_none.correct_ceiling_virtual = 0 self.dimension_none.correct_ceiling_reporting = 0 self.dimension_none.incorrect_virtual = 0 self.dimension_none.incorrect_reporting = 0 self.dimension_override = copy.copy(self.dimension) self.entities = { 'canonical_type_appended': canonical_entity(), 'noncanonical_type_appended': noncanonical_entity(), 'reporting': list( validator.Deserialize(['tests/samples/reporting_entity.yaml' ])[0].values())[0], 'virtual': list( validator.Deserialize(['tests/samples/virtual_entity.yaml' ])[0].values())[0], }
def __init__(self, *, ontology: str, solution: str, proposed: str, verbose: Optional[bool] = False): """ Arguments: ontology: Path to the ontology solution: Path to the solution config proposed: Path to the config to be evaluated verbose: Print specifics of missing types and translations (optional) """ self.args = { 'ontology': ontology, SOLUTION: solution, PROPOSED: proposed, 'verbose': verbose } self.universe = BuildUniverse(modified_types_filepath=ontology) self.deserialized_files = { PROPOSED: validator.Deserialize([proposed])[0], SOLUTION: validator.Deserialize([solution])[0] } self.results = {}
def testRetrieveReportingTranslations(self): proposed_entities = validator.Deserialize( ['tests/samples/proposed/retrieve_reporting_translations.yaml'])[0] solution_entities = validator.Deserialize( ['tests/samples/solution/retrieve_reporting_translations.yaml'])[0] # Allow solution entities past gate which has type annotation as a prereq with patch.object(Dimension, 'is_entity_canonical', return_value=True): translations = parse_config.ParseConfig.retrieve_reporting_translations( proposed_entities=proposed_entities, solution_entities=solution_entities) self.assertEqual(type(translations), dict) # TranslationsDict cdid = '2599571827844401' self.assertEqual(type(translations[cdid]), dict) self.assertTrue(f'{PROPOSED}' in translations[cdid]) self.assertEqual(type(translations[cdid][f'{PROPOSED}']), list) self.assertEqual(len(translations[cdid][f'{PROPOSED}']), 1) self.assertEqual(type(translations[cdid][f'{PROPOSED}'][0]), tuple) self.assertEqual(translations[cdid][f'{PROPOSED}'][0][0], 'wrong') self.assertEqual(type(translations[cdid][f'{PROPOSED}'][0][1]), NonDimensionalValue) self.assertTrue(f'{SOLUTION}' in translations[cdid]) self.assertEqual(type(translations[cdid][f'{SOLUTION}']), list) self.assertEqual(len(translations[cdid][f'{SOLUTION}']), 1) self.assertEqual(type(translations[cdid][f'{SOLUTION}'][0]), tuple) self.assertEqual(translations[cdid][f'{SOLUTION}'][0][0], 'target') self.assertEqual(type(translations[cdid][f'{SOLUTION}'][0][1]), NonDimensionalValue)
def testMatchReportingEntities(self): proposed_entities = validator.Deserialize( ['tests/samples/proposed/match_reporting_entities.yaml'])[0] solution_entities = validator.Deserialize( ['tests/samples/solution/match_reporting_entities.yaml'])[0] matches = parse_config.ParseConfig.match_reporting_entities( proposed_entities=proposed_entities, solution_entities=solution_entities) self.assertEqual(len(proposed_entities), 4) self.assertEqual(len(solution_entities), 4) self.assertEqual(len(matches), 1) self.assertEqual(matches[0], '2599571827844401') # Yes, it's a string
def noncanonical_entity() -> EntityInstance: entity = list( validator.Deserialize(['tests/samples/noncanonical_entity.yaml' ])[0].values())[0] # Append the type to be checked by is_entity_canonical() entity.type = BuildUniverse(use_simplified_universe=True).GetEntityType( entity.namespace, entity.type_name) return entity
def prepare_dimension_argument(*, dimension_type, proposed_path, solution_path): """Prepare argument for direct invocation of a dimension for purposes of testing (i.e. mimic parse_config.py). NOTE: this uses the simplified universe. If the test data references types which are not contained therein, results will differ from those which use the full universe because entities with missing types are skipped! Arguments: dimension_type: the dimension's category. (Literal[SIMPLE, COMPLEX]) proposed_path: the path to the proposed YAML file solution_path: the path to the solution YAML file Returns: The appropriate value for the dimension's singular named argument""" universe = BuildUniverse(use_simplified_universe=True) proposed_config = validator.Deserialize([proposed_path])[0] solution_config = validator.Deserialize([solution_path])[0] deserialized_files = { PROPOSED: proposed_config, SOLUTION: solution_config } deserialized_files_appended = ParseConfig.append_types( universe=universe, deserialized_files=deserialized_files) if dimension_type == SIMPLE: matches = ParseConfig.match_reporting_entities( proposed_entities=deserialized_files_appended[PROPOSED], solution_entities=deserialized_files_appended[SOLUTION]) translations = ParseConfig.retrieve_reporting_translations( matches=matches, proposed_entities=deserialized_files_appended[PROPOSED], solution_entities=deserialized_files_appended[SOLUTION]) return translations elif dimension_type == COMPLEX: return deserialized_files_appended
def testRetrieveReportingTranslations(self): proposed_entities = validator.Deserialize( ['tests/samples/proposed/retrieve_reporting_translations.yaml'])[0] solution_entities = validator.Deserialize( ['tests/samples/solution/retrieve_reporting_translations.yaml'])[0] matches = parse_config.ParseConfig.match_reporting_entities( proposed_entities=proposed_entities, solution_entities=solution_entities) translations = parse_config.ParseConfig.retrieve_reporting_translations( matches=matches, proposed_entities=proposed_entities, solution_entities=solution_entities) self.assertEqual(type(translations), dict) # TranslationsDict self.assertEqual(len(translations.items()), len(matches)) cdid = '2599571827844401' self.assertEqual(type(translations[cdid]), dict) self.assertTrue(f'{PROPOSED}' in translations[cdid]) self.assertEqual(type(translations[cdid][f'{PROPOSED}']), list) self.assertEqual(len(translations[cdid][f'{PROPOSED}']), 1) self.assertEqual(type(translations[cdid][f'{PROPOSED}'][0]), tuple) self.assertEqual(translations[cdid][f'{PROPOSED}'][0][0], 'wrong') self.assertEqual(type(translations[cdid][f'{PROPOSED}'][0][1]), NonDimensionalValue) self.assertTrue(f'{SOLUTION}' in translations[cdid]) self.assertEqual(type(translations[cdid][f'{SOLUTION}']), list) self.assertEqual(len(translations[cdid][f'{SOLUTION}']), 1) self.assertEqual(type(translations[cdid][f'{SOLUTION}'][0]), tuple) self.assertEqual(translations[cdid][f'{SOLUTION}'][0][0], 'target') self.assertEqual(type(translations[cdid][f'{SOLUTION}'][0][1]), NonDimensionalValue)