|
15 | 15 | deprecation_no_replacement, |
16 | 16 | mark_location, |
17 | 17 | matrix_multiply, |
| 18 | + parse_iso8824_date, |
18 | 19 | read_block_backwards, |
19 | 20 | read_previous_line, |
20 | 21 | read_until_regex, |
@@ -337,3 +338,33 @@ def test_file_class(): |
337 | 338 | f = File(name="image.png", data=b"") |
338 | 339 | assert str(f) == "File(name=image.png, data: 0 Byte)" |
339 | 340 | assert repr(f) == "File(name=image.png, data: 0 Byte, hash: 0)" |
| 341 | + |
| 342 | + |
| 343 | +@pytest.mark.parametrize( |
| 344 | + ("text", "expected"), |
| 345 | + [ |
| 346 | + ("D:20210318000756", "2021-03-18T00:07:56"), |
| 347 | + ("20210318000756", "2021-03-18T00:07:56"), |
| 348 | + ("D:2021", "2021-01-01T00:00:00"), |
| 349 | + ("D:202103", "2021-03-01T00:00:00"), |
| 350 | + ("D:20210304", "2021-03-04T00:00:00"), |
| 351 | + ("D:2021030402", "2021-03-04T02:00:00"), |
| 352 | + ("D:20210408054711", "2021-04-08T05:47:11"), |
| 353 | + ("D:20210408054711Z", "2021-04-08T05:47:11+00:00"), |
| 354 | + ("D:20210408054711Z00", "2021-04-08T05:47:11+00:00"), |
| 355 | + ("D:20210408054711Z0000", "2021-04-08T05:47:11+00:00"), |
| 356 | + ("D:20210408075331+02'00'", "2021-04-08T07:53:31+02:00"), |
| 357 | + ("D:20210408075331-03'00'", "2021-04-08T07:53:31-03:00"), |
| 358 | + ], |
| 359 | +) |
| 360 | +def test_parse_datetime(text, expected): |
| 361 | + date = parse_iso8824_date(text) |
| 362 | + date_str = (date.isoformat() + date.strftime("%z"))[: len(expected)] |
| 363 | + assert date_str == expected |
| 364 | + |
| 365 | + |
| 366 | +def test_parse_datetime_err(): |
| 367 | + with pytest.raises(ValueError) as ex: |
| 368 | + parse_iso8824_date("D:20210408T054711Z") |
| 369 | + assert ex.value.args[0] == "Can not convert date: D:20210408T054711Z" |
| 370 | + assert parse_iso8824_date("D:20210408054711").tzinfo is None |
0 commit comments