-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_cidoc_crm.py
73 lines (60 loc) · 2.26 KB
/
test_cidoc_crm.py
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
import pathlib
import types
import pytest
import rdflib
from undate import Undate, DatePrecision
from undate.converters import cidoc_crm
# TODO: move or copy example ismi data to test for use as a fixture
ISMI_DATA_PATH = (
pathlib.Path(__file__)
/ ".."
/ ".."
/ ".."
/ "examples"
/ "use-cases"
/ "ismi"
/ "data"
/ "ismi-crm-date-samples.ttl"
)
DATE1_URI = rdflib.URIRef("http://content.mpiwg-berlin.mpg.de/ns/ismi/date1")
@pytest.fixture
def ismi_data():
g = rdflib.Graph()
g.parse(ISMI_DATA_PATH)
return g
class TestTimeSpan:
def test_properties(self, ismi_data):
# initialize a time span rdflib.resource for date1 in the sample data
# TODO: convert to a fixture
# g = rdflib.Graph()
# g.parse(ISMI_DATA_PATH)
# g.parse(data=sample_data)
time_span = cidoc_crm.TimeSpan(ismi_data, DATE1_URI)
assert time_span.type == cidoc_crm.ISMI_DATE_TYPE.day
assert time_span.label == rdflib.term.Literal("901 Rabīʿ I 14 (islamic)")
assert time_span.calendar == cidoc_crm.ISMI_CALENDAR_TYPE.islamic
assert time_span.at_some_time_within == rdflib.term.Literal(
"1495-12-11", datatype=rdflib.XSD.date
)
assert time_span.note == rdflib.term.Literal(
"day-precision date in islamic calendar"
)
def test_time_spans_from_graph(self, ismi_data):
time_spans = cidoc_crm.TimeSpan.time_spans_from_graph(ismi_data)
assert isinstance(time_spans, types.GeneratorType)
time_spans = list(time_spans)
# fixture has 9 time spans
assert len(time_spans) == 9
assert isinstance(time_spans[0], cidoc_crm.TimeSpan)
assert time_spans[0].identifier == DATE1_URI
def test_to_undate(self, ismi_data):
time_span = cidoc_crm.TimeSpan(ismi_data, DATE1_URI)
ts_undate = time_span.to_undate()
assert isinstance(ts_undate, Undate)
# 1495-12-11"^^xsd:date ;
assert ts_undate.year == "1495"
assert ts_undate.month == "12"
assert ts_undate.day == "11"
assert ts_undate.precision == DatePrecision.DAY
# if we round trip the date it comes out the same
assert ts_undate.format("ISO8601") == str(time_span.at_some_time_within)