Ejemplo n.º 1
0
    def test__property(self):
        """Test the _property method.

        Also tests _compute_property implicitly.
        """
        namespace_registry = math._namespace_registry
        for data, restriction in zip(self.restriction_data, self.restrictions):
            data_property = namespace_registry.from_iri(data["property"])
            self.assertEqual(data_property, restriction._property)
Ejemplo n.º 2
0
    def test_rtype(self):
        """Test the rtype method.

        Also tests _compute_rtype implicitly.
        """
        namespace_registry = math._namespace_registry
        for data, restriction in zip(self.restriction_data, self.restrictions):
            data_property = namespace_registry.from_iri(data["property"])
            data_property_type = type(data_property)
            self.assertIs(rtypes[data_property_type], restriction.rtype)
Ejemplo n.º 3
0
    def test__property(self):
        """Test the _property method.

        Also tests _compute_property implicitly.
        """
        for r in self.iter_restrictions():
            b_node = r._bnode
            graph = r._graph
            namespace_registry = r._namespace_registry

            properties = graph.objects(
                subject=b_node, predicate=rdflib.OWL.onProperty
            )
            properties = list(properties)
            self.assertTrue(
                len(properties) == 1,
                "The restriction refers not " "exactly to one property.",
            )
            prop = namespace_registry.from_iri(properties[0])
            self.assertEqual(prop, r._property)
Ejemplo n.º 4
0
    def test_attribute_and_relationship(self):
        """Tests both the relationship and the attribute method*.

        Make sure that the __init__ method of this class instantiates at least
        one example of a restriction on a relationship and on an attribute so
        that all cases are covered.
        """
        namespace_registry = math._namespace_registry
        for data, restriction in zip(self.restriction_data, self.restrictions):
            data_property = namespace_registry.from_iri(data["property"])
            class_data_property = type(data_property)
            if rtypes[class_data_property] == RTYPE.RELATIONSHIP_RESTRICTION:
                self.assertRaises(
                    AttributeError, getattr, restriction, "attribute"
                )
            elif rtypes[class_data_property] == RTYPE.ATTRIBUTE_RESTRICTION:
                self.assertRaises(
                    AttributeError, getattr, restriction, "relationship"
                )
            else:
                raise Exception(
                    f"Incomplete test, restrictions of type "
                    f"{restriction.rtype} are not considered."
                )