summaryrefslogtreecommitdiff
path: root/test/test_extras/test_infixowl/test_componentterms.py
blob: ba1c0d61004d0d1605b2eba43d44685d027169a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import pytest

from rdflib import OWL, BNode, Graph, Namespace, URIRef
from rdflib.extras.infixowl import (
    BooleanClass,
    Class,
    ComponentTerms,
    Individual,
    Property,
    some,
)

EXNS = Namespace("http://example.org/vocab/")
PZNS = Namespace(
    "http://www.co-ode.org/ontologies/pizza/2005/10/18/classified/pizza.owl#"
)


@pytest.fixture(scope="function")
def graph():
    g = Graph(identifier=EXNS.context0)
    g.bind("ex", EXNS)
    Individual.factoryGraph = g

    yield g

    del g


def test_componentterms_restriction():
    name = EXNS.Man
    assert isinstance(name, URIRef)

    r = (
        (Property(EXNS.someProp, baseType=OWL.DatatypeProperty))
        @ some
        @ (Class(EXNS.Foo))
    )

    r.value = BNode("foo")

    ct = ComponentTerms(r)
    assert str(list(ct)) in ["[Class: ns1:Foo ]", "[Class: ex:Foo ]"]


def test_componentterms_booleanclass(graph):
    fire = Class(EXNS.Fire)
    water = Class(EXNS.Water)

    id = EXNS.randoboolclass

    bc = BooleanClass(identifier=id, members=[fire, water], graph=graph)

    ct = ComponentTerms(bc)

    assert str(list(ct)) == "[Class: ex:Fire , Class: ex:Water ]"


def test_componentterms_booleanclass_bnodeid(graph):
    fire = Class(EXNS.Fire)
    water = Class(EXNS.Water)

    id = BNode("randoboolclass")

    bc = BooleanClass(identifier=id, members=[fire, water], graph=graph)

    ct = ComponentTerms(bc)

    assert str(list(ct)) == "[Class: ex:Fire , Class: ex:Water ]"