Exemplo n.º 1
0
    def test_uri_and_curie(self):
        """ Compile a model of URI's and Curies and then test the various types """
        self.single_file_generator('py',
                                   PythonGenerator,
                                   filtr=metadata_filter,
                                   comparator=compare_python)

        # Check that the interpretations are correct
        self.single_file_generator(
            'jsonld',
            ContextGenerator,
            filtr=ldcontext_metadata_filter,
            comparator=lambda expected, actual: compare_rdf(
                expected, actual, fmt="json-ld"))
        self.single_file_generator('json',
                                   JSONLDGenerator,
                                   filtr=json_metadata_filter)

        module = compile_python(env.expected_path(self.model_name + '.py'))

        curie_obj = module.C1("ex:obj1",
                              hasCurie="ex:curie",
                              hasURI="http://example.org/test/uri",
                              hasNcName="A123",
                              id2="ex:id2")
        instance_jsonld = loads('{ "ex": "http://example.org/test/inst#" }')

        g = as_rdf(
            curie_obj,
            [env.input_path(self.model_name + '.jsonld'), instance_jsonld])
        env.eval_single_file(env.expected_path('uriandcurie.ttl'),
                             g.serialize(format='ttl').decode(), lambda s: s,
                             compare_rdf)
Exemplo n.º 2
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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
    def test_element_slots(self):
        """ Test all element slots and their inheritence """
        schema = SchemaLoader(env.input_path('resolver3.yaml')).resolve()
        x = {
            k: v
            for k, v in as_dict(schema.slots['s1']).items()
            if v is not None and v != []
        }
        outfile = env.expected_path('resolver3.json')
        if not os.path.exists(outfile):
            with open(outfile, 'w') as f:
                f.write(as_json(JsonObj(**x)))
        with open(outfile) as f:
            expected = as_dict(load(f))

        self.assertEqual(expected, x)
Exemplo n.º 5
0
        def check_types(s: SchemaDefinition) -> None:
            output = env.expected_path('schema4.json')
            if not os.path.exists(output):
                with open(output, 'w') as f:
                    f.write(
                        as_json(
                            JsonObj(
                                **{
                                    k: as_dict(loads(as_json(v)))
                                    for k, v in s.types.items()
                                })))

            with open(output) as f:
                expected = as_dict(load(f))
            self.assertEqual(
                expected,
                {k: as_dict(loads(as_json(v)))
                 for k, v in s.types.items()})
            s.types = None
Exemplo n.º 6
0
 def test_as_json(self):
     schema = self.fix_schema_metadata(
         load_raw_schema(env.input_path('schema6.yaml')))
     env.eval_single_file(env.expected_path('schema6.json'),
                          as_json(schema),
                          filtr=lambda s: s)