Skip to content

Commit aa38603

Browse files
committed
Use full ismi sample data as test fixture
1 parent 6f10c67 commit aa38603

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

tests/test_converters/test_cidoc_crm.py

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
1+
import pathlib
12
import types
23

4+
import pytest
35
import rdflib
46

57
from undate import Undate, DatePrecision
68
from undate.converters import cidoc_crm
79

810

9-
# TODO: maybe copy full example ismi data as fixture
10-
# so we have examples of all types to test against
11+
# TODO: move or copy example ismi data to test for use as a fixture
12+
ISMI_DATA_PATH = (
13+
pathlib.Path(__file__)
14+
/ ".."
15+
/ ".."
16+
/ ".."
17+
/ "examples"
18+
/ "use-cases"
19+
/ "ismi"
20+
/ "data"
21+
/ "ismi-crm-date-samples.ttl"
22+
)
1123

12-
sample_data = """
13-
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
14-
@prefix crm: <http://www.cidoc-crm.org/cidoc-crm/> .
15-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16-
# prefix for date and calendar type URIs
17-
@prefix datetype: <http://content.mpiwg-berlin.mpg.de/ns/ismi/type/date/> .
18-
@prefix calendartype: <http://content.mpiwg-berlin.mpg.de/ns/ismi/type/calendar/> .
19-
# prefix for sample data
20-
@prefix : <http://content.mpiwg-berlin.mpg.de/ns/ismi/> .
24+
DATE1_URI = rdflib.URIRef("http://content.mpiwg-berlin.mpg.de/ns/ismi/date1")
2125

22-
# day-precision date in islamic calendar
23-
:date1 a crm:E52_Time-Span ;
24-
crm:P2_has_type datetype:day ;
25-
crm:P82_at_some_time_within "1495-12-11"^^xsd:date ;
26-
crm:P3_has_note "day-precision date in islamic calendar" ;
27-
crm:P1_is_identified_by :date1-label .
28-
:date1-label a crm:E41_Appellation ;
29-
crm:P2_has_type calendartype:islamic ;
30-
rdfs:label "901 Rabīʿ I 14 (islamic)" .
31-
"""
3226

33-
ISMI_NS = rdflib.Namespace("http://content.mpiwg-berlin.mpg.de/ns/ismi/")
34-
DATE1_URI = rdflib.URIRef("http://content.mpiwg-berlin.mpg.de/ns/ismi/date1")
27+
@pytest.fixture
28+
def ismi_data():
29+
g = rdflib.Graph()
30+
g.parse(ISMI_DATA_PATH)
31+
return g
3532

3633

3734
class TestTimeSpan:
38-
def test_properties(self):
35+
def test_properties(self, ismi_data):
3936
# initialize a time span rdflib.resource for date1 in the sample data
4037
# TODO: convert to a fixture
41-
g = rdflib.Graph()
42-
g.parse(data=sample_data)
38+
# g = rdflib.Graph()
39+
# g.parse(ISMI_DATA_PATH)
40+
# g.parse(data=sample_data)
4341

44-
time_span = cidoc_crm.TimeSpan(g, DATE1_URI)
42+
time_span = cidoc_crm.TimeSpan(ismi_data, DATE1_URI)
4543
assert time_span.type == cidoc_crm.ISMI_DATE_TYPE.day
4644
assert time_span.label == rdflib.term.Literal("901 Rabīʿ I 14 (islamic)")
4745
assert time_span.calendar == cidoc_crm.ISMI_CALENDAR_TYPE.islamic
@@ -52,22 +50,17 @@ def test_properties(self):
5250
"day-precision date in islamic calendar"
5351
)
5452

55-
def test_time_spans_from_graph(self):
56-
g = rdflib.Graph()
57-
g.parse(data=sample_data)
58-
59-
time_spans = cidoc_crm.TimeSpan.time_spans_from_graph(g)
53+
def test_time_spans_from_graph(self, ismi_data):
54+
time_spans = cidoc_crm.TimeSpan.time_spans_from_graph(ismi_data)
6055
assert isinstance(time_spans, types.GeneratorType)
6156
time_spans = list(time_spans)
62-
assert len(time_spans) == 1
57+
# fixture has 9 time spans
58+
assert len(time_spans) == 9
6359
assert isinstance(time_spans[0], cidoc_crm.TimeSpan)
6460
assert time_spans[0].identifier == DATE1_URI
6561

66-
def test_to_undate(self):
67-
g = rdflib.Graph()
68-
g.parse(data=sample_data)
69-
70-
time_span = cidoc_crm.TimeSpan(g, DATE1_URI)
62+
def test_to_undate(self, ismi_data):
63+
time_span = cidoc_crm.TimeSpan(ismi_data, DATE1_URI)
7164
ts_undate = time_span.to_undate()
7265
assert isinstance(ts_undate, Undate)
7366
# 1495-12-11"^^xsd:date ;

0 commit comments

Comments
 (0)