def test_contained_constructor(self):
        test_name = 'issue_355'
        """ Make sure that types are generated as part of the output """
        env.generate_single_file(f'{test_name}.py',
                                 lambda: PythonGenerator(env.input_path(f'{test_name}.yaml')).serialize(),
                                 comparator=lambda exp, act: compare_python(exp, act, self.env.expected_path(f'{test_name}.py')),
                                 value_is_returned=True)
        module = compile_python(env.expected_path(f'{test_name}.py'))
        c = module.Container(module.Containee('11111', "Glaubner's disease"))
        self.assertEqual('''entry:
  '11111':
    id: '11111'
    value: Glaubner's disease''', as_yaml(c).strip())

        c = module.Container({'22222': dict(id='22222', value='Phrenooscopy')})
        self.assertEqual('''entry:
  '22222':
    id: '22222'
    value: Phrenooscopy''', as_yaml(c).strip())
        alt_object = YAMLRoot()
        alt_object.id = '33333'
        alt_object.value = 'test'
        c = module.Container(alt_object)
        self.assertEqual('''entry:
  '33333':
    id: '33333'
    value: test''', as_yaml(c).strip())
        c = module.Container([dict(id='44444', value="Gracken's curse")])
        self.assertEqual('''entry:
  '44444':
    id: '44444'
    value: Gracken's curse''', as_yaml(c).strip())
    def test_as_yaml(self):
        """ Test the YAML output representation """
        schema = self.fix_schema_metadata(
            load_raw_schema(os.path.join(inputdir, 'schema4.yaml')))
        outfile = os.path.join(outputdir, 'schema4.yaml')
        if not os.path.exists(outfile):
            with open(outfile, 'w') as f:
                f.write(as_yaml(schema))
            self.fail(f"Output file: {outfile} created - run test again")

        with open(outfile) as f:
            self.assertEqual(f.read(), as_yaml(schema))
Beispiel #3
0
 def test_inverse_mismatch(self):
     """ Test error detection when inverses don't match """
     with self.assertRaises(ValueError) as e:
         env.generate_single_file('issue_18_error1.yaml',
                                  lambda: as_yaml(SchemaLoader(env.input_path('issue_18_error1.yaml')).resolve()),
                                  value_is_returned=True)
     self.assertEqual('Slot s1.inverse (s2) does not match slot s2.inverse (s3)', str(e.exception).strip())
Beispiel #4
0
 def test_no_inverse_domain(self):
     with self.assertRaises(ValueError) as e:
         env.generate_single_file('issue_18_error3.yaml',
                                  lambda: as_yaml(SchemaLoader(env.input_path('issue_18_error3.yaml')).resolve()),
                                  value_is_returned=True)
     self.assertEqual("Unable to determine the range of slot `s1'. Its inverse (s2) has no declared domain",
                      str(e.exception).strip())
Beispiel #5
0
    def test_as_yaml(self):
        """ Test the YAML output representation """
        schema = self.fix_schema_metadata(
            load_raw_schema(os.path.join(datadir, 'schema4.yaml')))

        self.assertEqual(
            """generation_date: 2018-12-31 17:23
id: !!python/object/new:biolinkml.utils.metamodelcore.URI
- http://example.org/schema4
metamodel_version: 0.5.0
name: !!python/object/new:biolinkml.meta.SchemaDefinitionName
- schema4
source_file: schema4.yaml
source_file_date: 2018-12-31 17:23
source_file_size: 259
title: Load Raw Schema Test
types:
  integer:
    base: int
    from_schema: !!python/object/new:biolinkml.utils.metamodelcore.URI
    - http://example.org/schema5
    name: !!python/object/new:biolinkml.meta.TypeDefinitionName
    - integer
  string:
    base: str
    from_schema: !!python/object/new:biolinkml.utils.metamodelcore.URI
    - http://example.org/schema4
    name: !!python/object/new:biolinkml.meta.TypeDefinitionName
    - string
""", as_yaml(schema))
Beispiel #6
0
 def test_as_yaml(self):
     """ Test the YAML output representation """
     schema = self.fix_schema_metadata(
         load_raw_schema(env.input_path('schema4.yaml')))
     env.eval_single_file(env.expected_path('schema4.yaml'),
                          as_yaml(schema),
                          filtr=lambda s: s)
 def test_multi_usages_2(self):
     """ Slot usage chain with starting alias """
     schema = SchemaLoader(env.input_path('multi_usages_2.yaml')).resolve()
     self._eval_expected(schema, 's1', 'value', 'root_class', None, None, 'string')
     self._eval_expected(schema, 'child_class1_s1', 'value', 'child_class1', 's1', 's1', 'boolean')
     self._eval_expected(schema, 'child_class2_s1', 'value', 'child_class2', 'child_class1_s1', 's1', 'integer')
     self._eval_expected(schema, 'child_class3_s1', 'value', 'child_class3', 'child_class2_s1', 's1', 'integer')
     env.eval_single_file(env.expected_path('multi_usages_2.yaml'), as_yaml(schema), filtr=yaml_filter)
 def test_issue_177_dup(self):
     env.generate_single_file(
         'issue_177_error.yaml',
         lambda: as_yaml(
             SchemaLoader(env.input_path('issue_177_error.yaml')).resolve()
         ),
         value_is_returned=True,
         filtr=yaml_filter)
Beispiel #9
0
 def test_multi_domains(self):
     with self.redirect_logstream() as logger:
         env.generate_single_file('issue_18_warning1.yaml',
                                  lambda: as_yaml(SchemaLoader(env.input_path('issue_18_warning1.yaml'),
                                                               logger=logger).resolve()),
                                  filtr=yaml_filter, value_is_returned=True)
     self.assertIn('Slot s2.inverse (s1), has multi domains (c1, c2)  Multi ranges not yet implemented',
                   logger.result)
Beispiel #10
0
 def test_issue_167(self):
     """ Test extensions to the four basic types """
     env.generate_single_file(
         'issue_167.yaml',
         lambda: as_yaml(
             SchemaLoader(env.input_path('issue_167.yaml')).resolve()),
         value_is_returned=True,
         filtr=yaml_filter)
Beispiel #11
0
 def test_issue_167b_yaml(self):
     """ Annotations yaml example """
     env.generate_single_file(
         'issue_167b.yaml',
         lambda: as_yaml(
             SchemaLoader(env.input_path('issue_167b.yaml'),
                          importmap=env.import_map).resolve()),
         value_is_returned=True,
         filtr=yaml_filter)
Beispiel #12
0
 def test_issue_58(self):
     """ Reject non NSNAME model names"""
     with self.assertRaises(ValueError) as ve:
         env.generate_single_file(
             'issue_58_error1.yaml',
             lambda: as_yaml(
                 SchemaLoader(env.input_path('issue_58_error1.yaml')).
                 resolve()),
             value_is_returned=True)
     self.assertIn('issue 58: Not a valid NCName', str(ve.exception))
Beispiel #13
0
 def test_minimal_definition(self):
     entry = SpecificEntityList("http://loinc.org/",
                                entities={
                                    'abc': None,
                                    'def': None
                                })
     vde = ValueSetDefinitionEntry(include=entry)
     defn = ValueSetDefinition(resourceID="SIMPLE",
                               about="http://something.org/smthing",
                               entry=[vde])
     print(as_yaml(defn))
Beispiel #14
0
 def test_code_system(self):
     hpo = CodeSystemReference('HPO',
                               'Human Phenotype Ontology',
                               href='https://hpo.jax.org/app/')
     entry = CompleteCodeSystemReference(hpo)
     vde = ValueSetDefinitionEntry(include=entry)
     defn = ValueSetDefinition(
         'HPO',
         about="http://ontologies.r.us/valueset/allofHPO",
         entry=[vde])
     print(as_yaml(defn))
     print(dump(defn))
Beispiel #15
0
    def test_roundtrip(self):
        """ Test as_yaml emitter """
        # env.generate_single_file('issue_154.py',
        #                          lambda: PythonGenerator(env.input_path('issue_134.yaml')).serialize(),
        #                          comparator=compare_python, value_is_returned=True)
        # yaml_fname = env.input_path('issue_134.yaml')

        # We use the PythonGenerator as a generic generator instance.  We don't actually serialize

        yaml_fname = env.input_path('issue_134.yaml')
        gen = PythonGenerator(yaml_fname)
        yaml_str = as_yaml(gen.schema)
        generated = yaml.safe_load(yaml_str)
        with open(yaml_fname) as yaml_file:
            original = yaml.safe_load(yaml_file)

        # The generated YAML contains many added fields. Some with default values. Therefore, we can't directly
        # compare it to the original.
        for key in original:
            self.assertEqual(len(original[key]), len(generated[key]))
            if isinstance(original[key], dict):
                for subkey in original[key]:
                    self.assertTrue(subkey in generated[key])
Beispiel #16
0
 def test_missing_inverse(self):
     with self.assertRaises(ValueError) as e:
         env.generate_single_file('issue_18_error2.yaml',
                                  lambda: as_yaml(SchemaLoader(env.input_path('issue_18_error2.yaml')).resolve()),
                                  value_is_returned=True)
     self.assertEqual('Slot s1.inverse (s2) is not defined', str(e.exception).strip())
Beispiel #17
0
 def serialize(self, validateonly: bool = False, **kwargs) -> str:
     if validateonly:
         return self.synopsis.summary()
     else:
         return as_yaml(self.schema)
Beispiel #18
0
 def test_issue_18(self):
     """ Make sure that inverses are automatically generated """
     env.generate_single_file('issue_18.yaml',
                              lambda: as_yaml(SchemaLoader(env.input_path('issue_18.yaml')).resolve()),
                              filtr=yaml_filter, value_is_returned=True)
Beispiel #19
0
 def end_class(self, cls: ClassDefinition) -> None:
     fn = os.path.join(self.dirname, underscore(cls.name + '-config.yaml'))
     with open(fn, 'w') as f:
         f.write(as_yaml(self.class_obj))