Skip to content

Commit acc39ea

Browse files
committed
tests: Update test to reflect date-parsing in current rdflib
Some of the dates/datetimes that were specified incorrectly or with the wrong datatype could no longer be parsed from the graph, because rdflib already threw an error due to the mismatched datatype. In this case, the values never get to our _clean_datetime method to be parsed by isodate. I have tried to update the fixture and the test to reflect the full range of what badly-specified dates/datetimes can be massaged into some kind of shape by our code, and which can't. Of course, the solution is that everyone should just do the right thing all the time.
1 parent ac566d8 commit acc39ea

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

ckanext/dcatapchharvest/tests/fixtures/dataset-datetimes-bad.xml

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,61 @@
3434
<schema:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">1997</schema:endDate>
3535
</dct:PeriodOfTime>
3636
</dct:temporal>
37-
<!-- using xsd:date, xsd:gYearMonth or xsd:gYear, but incorrectly specifying date: will be parsed as isodate as
38-
far as possible when rdflib creates the graph and will be mapped, but values might not be what the data publisher
39-
expected. -->
37+
<!-- using xsd:date, xsd:gYearMonth or xsd:gYear, but incorrectly specifying date: will not be mapped -->
4038
<dct:temporal>
4139
<dct:PeriodOfTime>
42-
<schema:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">1998-04</schema:startDate>
43-
<schema:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">1999</schema:endDate>
40+
<schema:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">1998</schema:startDate>
41+
<schema:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">1999-4-4</schema:endDate>
4442
</dct:PeriodOfTime>
4543
</dct:temporal>
4644
<dct:temporal>
4745
<dct:PeriodOfTime>
48-
<schema:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2000-11-21T01:02:03</schema:startDate>
49-
<schema:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2001T01:02:03</schema:endDate>
46+
<dcat:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2000-4</dcat:startDate>
47+
<dcat:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2001-6-06</dcat:endDate>
5048
</dct:PeriodOfTime>
5149
</dct:temporal>
5250
<dct:temporal>
5351
<dct:PeriodOfTime>
54-
<dcat:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2002-01-01T00:00:00</dcat:startDate>
52+
<dcat:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2002-01T00:00:00</dcat:startDate>
5553
<dcat:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2003</dcat:endDate>
5654
</dct:PeriodOfTime>
5755
</dct:temporal>
5856
<dct:temporal>
5957
<dct:PeriodOfTime>
60-
<dcat:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYear">2004-01-02</dcat:startDate>
61-
<dcat:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYear">2005-12</dcat:endDate>
58+
<dcat:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2004-4-1</dcat:startDate>
59+
<dcat:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2005-6-6</dcat:endDate>
6260
</dct:PeriodOfTime>
6361
</dct:temporal>
62+
<!-- using xsd:gYear, but incorrectly specifying date: will be parsed as isodate as far as possible when rdflib
63+
creates the graph and will be mapped, but values might not be what the data publisher expected. -->
6464
<dct:temporal>
6565
<dct:PeriodOfTime>
66-
<dcat:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2006-4</dcat:startDate>
67-
<dcat:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2007-6-6</dcat:endDate>
66+
<schema:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2006-11-21T01:02:03</schema:startDate>
67+
<schema:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2007-11T01:02:03</schema:endDate>
68+
</dct:PeriodOfTime>
69+
</dct:temporal>
70+
<dct:temporal>
71+
<dct:PeriodOfTime>
72+
<dcat:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYear">2008-04-02</dcat:startDate>
73+
<dcat:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYear">2009-06</dcat:endDate>
74+
</dct:PeriodOfTime>
75+
</dct:temporal>
76+
<dct:temporal>
77+
<dct:PeriodOfTime>
78+
<schema:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2010-04</schema:startDate>
79+
<schema:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2011-05</schema:endDate>
80+
</dct:PeriodOfTime>
81+
</dct:temporal>
82+
<dct:temporal>
83+
<dct:PeriodOfTime>
84+
<schema:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2012-11-21T01:02:03</schema:startDate>
85+
<schema:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2013-11-21T01:02:03</schema:endDate>
86+
</dct:PeriodOfTime>
87+
</dct:temporal>
88+
<dct:temporal>
89+
<dct:PeriodOfTime>
90+
<dcat:startDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2014-04-06T00:00:00</dcat:startDate>
91+
<dcat:endDate rdf:datatype="http://www.w3.org/2001/XMLSchema#gYearMonth">2015-01-02</dcat:endDate>
6892
</dct:PeriodOfTime>
6993
</dct:temporal>
7094
<!-- using XSD datatypes, with an invalid date or datetime: should not be mapped -->

ckanext/dcatapchharvest/tests/test_dcatap_ch_parse.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -398,26 +398,26 @@ def test_temporals_incorrect_formats(self):
398398
dataset = [d for d in p.datasets()][0]
399399
assert len(dataset["temporals"]) == 5
400400

401-
assert sorted(dataset["temporals"]) == [
401+
assert sorted(dataset["temporals"], key=lambda x: x["start_date"]) == [
402402
{
403-
"start_date": "1998-04-01T00:00:00",
404-
"end_date": "1999-01-01T23:59:59.999999",
403+
"start_date": "2006-11-21T00:00:00",
404+
"end_date": "2007-11-01T23:59:59.999999",
405405
},
406406
{
407-
"start_date": "2000-11-21T00:00:00",
408-
"end_date": "2001-01-01T23:59:59.999999",
407+
"start_date": "2008-01-01T00:00:00",
408+
"end_date": "2009-12-31T23:59:59.999999",
409409
},
410410
{
411-
"start_date": "2002-01-01T00:00:00",
412-
"end_date": "2003-01-31T23:59:59.999999",
411+
"start_date": "2010-04-01T00:00:00",
412+
"end_date": "2011-05-01T23:59:59.999999",
413413
},
414414
{
415-
"start_date": "2004-01-01T00:00:00",
416-
"end_date": "2005-12-31T23:59:59.999999",
415+
"start_date": "2012-11-21T00:00:00",
416+
"end_date": "2013-11-21T23:59:59.999999",
417417
},
418418
{
419-
"start_date": "2006-01-01T00:00:00",
420-
"end_date": "2007-01-31T23:59:59.999999",
419+
"start_date": "2014-04-01T00:00:00",
420+
"end_date": "2015-01-31T23:59:59.999999",
421421
},
422422
]
423423

0 commit comments

Comments
 (0)