|
4 | 4 | from time import struct_time |
5 | 5 |
|
6 | 6 | 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 |
8 | 10 |
|
9 | 11 |
|
10 | 12 | def test_dt_to_struct_time_for_datetime(): |
@@ -151,3 +153,31 @@ def no_remappings(): |
151 | 153 | raise AssertionError( |
152 | 154 | "expected ValueError from @remapparams() because p1 remaps to another remapped parameter" |
153 | 155 | ) |
| 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