]>
dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-datetimes.py
52da22c48b7294cd35623b0a5cd986089a7eb9da
2 """Independent integer/calendar/string DateTime oracle; no float or local timezone."""
6 from pathlib
import Path
9 import xml
.etree
.ElementTree
as ET
10 if hasattr(sys
, 'set_int_max_str_digits'):
11 sys
.set_int_max_str_digits(0)
12 root
= Path(__file__
).resolve().parent
.parent
13 r
= json
.loads(Path(sys
.argv
[1]).read_text())
14 assert r
['kind'] == 'datetime-semantic-and-cxtm-evidence' and r
['failed'] == 0
15 assert len(r
['checks']) == len(set(r
['checks'])) == r
['passed']
16 values
= ['1976-09-19T12:01:01', '1976-09-19T12:02:00', '2011-01-01T00:00:00.001', '2011-01-01T00:00:00Z']
17 for c
, value
in zip(r
['cases'], values
):
18 assert c
['ctmSource'].encode() == (root
/ 'vendor/cxtm' / c
['id']).read_bytes()
19 items
= [o
for t
in c
['actualObjects']['topics'] for o
in t
['occurrences']]
20 assert len(items
) == 1 and items
[0]['value'] == value
21 assert items
[0]['datatype'] == 'http://www.w3.org/2001/XMLSchema#dateTime'
22 assert c
['status'] == ('fail' if c
['id'].endswith('datetime2.ctm') else 'pass')
23 assert len(r
['cases']) == 4
27 m
= re
.fullmatch(r
'(-?[0-9]{4,})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.([0-9]+))?(Z|[+-]00:00)?', text
)
28 assert m
, 'oracle only called for supported lexical probes'
29 year
, month
, day
, hour
, minute
, second
, fraction
, zone
= m
.groups()
30 y
, mo
, d
, h
, mi
, se
= map(int, (year
, month
, day
, hour
, minute
, second
))
31 fraction
= (fraction
or '').rstrip('0')
32 leap
= se
== 60 and zone
and h
== 23 and mi
== 59 and (mo
, d
) in [(3,31), (6,30), (9,30), (12,31)]
33 if se
== 60 and not leap
:
34 assert (mo
, d
) not in [(3,31), (4,1), (6,30), (7,1), (9,30), (10,1), (12,31), (1,1)]
40 days
= [31, 29 if calendar
.isleap(y
) else 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][mo
-1]
46 ys
= ('-' if y
< 0 else '') + str(abs(y
)).zfill(4)
47 return f
'{ys}-{mo:02d}-{d:02d}T{h:02d}:{mi:02d}:{se:02d}' + ('.'+fraction
if fraction
else '') + ('Z' if zone
else '')
50 for p
in r
['lexicalProbes']:
51 expected
= canonical(p
['input'])
52 assert expected
== p
['canonicalValue']
53 assert p
['storedValue'] == (expected
if p
['mode'] == 'bare' else ' '+p
['input']+'\t' if p
['mode'] == 'qualified' else p
['input'])
54 items
= ET
.fromstring(p
['actualCXTM']).findall('topic/occurrence')
55 assert len(items
) == 1 and items
[0].findtext('value') == expected
56 assert items
[0].findtext('datatype') == 'http://www.w3.org/2001/XMLSchema#dateTime'
57 offset
= r
['unsupportedConstructObservations']
58 assert offset
['conditionClass'] == 'CTM-UNSUPPORTED' and offset
['code'] == 'DATETIME-TIMEZONE-CANONICALIZATION'
59 assert offset
['contractStatus'] == 'not-run' and offset
['normativeCanonicalValue'] == '2010-12-31T22:00:00Z'
60 assert offset
['ctmSource'].encode() == (root
/ 'vendor/cxtm' / offset
['id']).read_bytes()
61 assert offset
['upstreamCXTM'].encode() == (root
/ 'vendor/cxtm/ctm/baseline/occurrence-datetime-timezone2.ctm.cxtm').read_bytes()
62 assert [x
['contractStatus'] for x
in r
['normativeDiscrepancies']] == ['fail', 'not-run']
63 assert datetime
.datetime(2011,1,1,tzinfo
=datetime
.timezone(datetime
.timedelta(hours
=2))).astimezone(datetime
.timezone
.utc
).isoformat() == '2010-12-31T22:00:00+00:00'
64 print(f
'DATETIME-INDEPENDENT-PASS: {len(r["cases"])} original model observations; {len(r["lexicalProbes"])} exact calendar/fraction probes; 2 documented discrepancies')