summaryrefslogtreecommitdiff
path: root/test/test_extras/test_infixowl/test_individual.py
blob: 3937fdffba695041bf1de3897ca39af5f65dbc91 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from test.data import context0, pizza

import pytest

from rdflib import OWL, RDFS, BNode, Graph, Literal, Namespace, URIRef
from rdflib.extras.infixowl import Class, Individual

EXNS = Namespace("http://example.org/vocab/")


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

    yield g

    del g


def test_infixowl_individual_type(graph):
    b = Individual(OWL.Restriction, graph)
    b.type = RDFS.Resource
    assert len(list(b.type)) == 1

    del b.type
    assert len(list(b.type)) == 0


def test_infixowl_individual_label(graph):
    b = Individual(OWL.Restriction, graph)
    b.label = Literal("boo")

    assert len(list(b.label)) == 3

    del b.label
    assert hasattr(b, "label") is False


def test_individual_type_settergetter(graph):
    b = Individual(OWL.Restriction, graph)

    b.type = OWL.Restriction

    b.type = None

    b.type = OWL.Class

    b.type = [OWL.Class, OWL.Restriction]

    assert graph.serialize(format="ttl") == (
        "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n"
        "\n"
        "owl:Restriction a owl:Class,\n"
        "        owl:Restriction .\n"
        "\n"
    )

    b.replace(Class(identifier=context0))

    assert graph.serialize(format="ttl") == (
        "@prefix ns1: <urn:example:> .\n"
        "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n"
        "\n"
        "ns1:context-0 a owl:Class .\n"
        "\n"
    )


def test_individual_identity__settergetter(graph):
    b = Individual(OWL.Restriction, graph)

    assert b.identifier == URIRef("http://www.w3.org/2002/07/owl#Restriction")

    b.identifier = URIRef("http://www.w3.org/2002/07/owl#Restriction")

    b.identifier = pizza

    assert b.identifier == pizza

    b.identifier = URIRef("http://www.w3.org/2002/07/owl#Restriction")

    bnodeid = BNode("harry")

    b.identifier = bnodeid

    assert b.identifier == bnodeid


def test_individual_sameas__settergetter(graph):
    b = Individual(OWL.Restriction, graph)

    assert list(b.sameAs) == []

    b.sameAs = pizza

    assert list(b.sameAs) == [pizza]

    bnodeid = BNode("harry")

    b.sameAs = [pizza, bnodeid]

    assert list(b.sameAs) == [pizza, bnodeid]