Skip to content

Commit dedb361

Browse files
edtf.tests: exercise parse_edtf using the obsolete and modern mode parameters
1 parent f4a73fe commit dedb361

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

edtf/tests.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from time import struct_time
55

66
from edtf import convert
7-
from edtf.utils import remapparams
7+
from edtf.parser.edtf_exceptions import EDTFParseException
8+
from edtf.parser.grammar import parse_edtf
9+
from edtf.util import remapparams
810

911

1012
def test_dt_to_struct_time_for_datetime():
@@ -151,3 +153,31 @@ def no_remappings():
151153
raise AssertionError(
152154
"expected ValueError from @remapparams() because p1 remaps to another remapped parameter"
153155
)
156+
157+
def test_remapparams_parse_edtf():
158+
edtf_s = '2005-09-24T10:00:00' # ISO8601 example from the EDTF spec
159+
dat = parse_edtf(edtf_s) # implicit parse_all=True
160+
assert dat.isoformat() == edtf_s
161+
assert parse_edtf(edtf_s, parse_all=True).isoformat() == edtf_s
162+
assert parse_edtf(edtf_s, parseAll=True).isoformat() == edtf_s
163+
assert parse_edtf(f'{edtf_s} SNORT', parse_all=False).isoformat() == edtf_s
164+
assert parse_edtf(f'{edtf_s} SNORT', parseAll=False).isoformat() == edtf_s
165+
# make sure parse_all=True fails the SNORT parse
166+
try:
167+
parse_edtf(f'{edtf_s} SNORT')
168+
except EDTFParseException:
169+
pass
170+
else:
171+
raise AssertionError('expected EDTFParseException')
172+
try:
173+
parse_edtf(f'{edtf_s} SNORT', parse_all=True)
174+
except EDTFParseException:
175+
pass
176+
else:
177+
raise AssertionError('expected EDTFParseException')
178+
try:
179+
parse_edtf(f'{edtf_s} SNORT', parseAll=True)
180+
except EDTFParseException:
181+
pass
182+
else:
183+
raise AssertionError('expected EDTFParseException')

0 commit comments

Comments
 (0)