|
240 | 240 | "2001-29", |
241 | 241 | ) |
242 | 242 |
|
| 243 | +APPROXIMATE_UNCERTAIN_EXAMPLES = ( |
| 244 | + # first part of tuple is the input EDTF string, second part is a tuple of booleans: |
| 245 | + # uncertain ?, approximate ~, both uncertain and approximate % |
| 246 | + ("2004", (False, False, False)), |
| 247 | + ("2006-06-11", (False, False, False)), |
| 248 | + ("-0999", (False, False, False)), |
| 249 | + ("1984?", (True, False, False)), |
| 250 | + ("2004-06-11?", (True, False, False)), |
| 251 | + ("1984~", (False, True, False)), |
| 252 | + ("1984%", (False, False, True)), |
| 253 | + ("1984~/2004-06", (False, True, False)), |
| 254 | + ("2004-%06", (False, False, True)), |
| 255 | + ("2004?-~06-~04", (True, True, False)), |
| 256 | + ("2004?-06-04", (True, False, False)), |
| 257 | + ("2011-~06-~04", (False, True, False)), |
| 258 | + ("2004-06-~01/2004-06-~20", (False, True, False)), |
| 259 | + ("156X~", (False, True, False)), |
| 260 | +) |
| 261 | + |
243 | 262 | BAD_EXAMPLES = ( |
244 | 263 | # parentheses are not used for group qualification in the 2018 spec |
245 | 264 | None, |
@@ -379,3 +398,17 @@ def test_comparisons(): |
379 | 398 | def test_benchmark_parser(benchmark, test_input): |
380 | 399 | """Benchmark parsing of selected EDTF strings.""" |
381 | 400 | benchmark(parse, test_input) |
| 401 | + |
| 402 | + |
| 403 | +@pytest.mark.parametrize("test_input,expected_tuple", APPROXIMATE_UNCERTAIN_EXAMPLES) |
| 404 | +def test_approximate_uncertain(test_input, expected_tuple): |
| 405 | + """Test parsing of EDTF strings and check .is_uncertain, .is_approximate, |
| 406 | + and .is_uncertain_and_approximate properties. The expected_tuple should have three |
| 407 | + values, the first should be a boolean indicating if the date is uncertain, |
| 408 | + the second should be a boolean indicating if the date is approximate, and the |
| 409 | + third should be a boolean indicating if the date is both uncertain and approximate.""" |
| 410 | + result = parse(test_input) |
| 411 | + assert isinstance(result, EDTFObject), "Result should be an instance of EDTFObject" |
| 412 | + assert result.is_uncertain == expected_tuple[0] |
| 413 | + assert result.is_approximate == expected_tuple[1] |
| 414 | + assert result.is_uncertain_and_approximate == expected_tuple[2] |
0 commit comments