Ejemplo n.º 1
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 = {}
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
    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