|
7 | 7 | from unittest import mock
|
8 | 8 |
|
9 | 9 | import pytest
|
| 10 | +from dateutil.parser import ParserError |
10 | 11 |
|
11 | 12 | from parsons import Table
|
12 | 13 | from parsons.utilities import check_env, files, json_format, sql_helpers
|
|
18 | 19 | [
|
19 | 20 | pytest.param("2018-12-13", 1544659200),
|
20 | 21 | pytest.param("2018-12-13T00:00:00-08:00", 1544688000),
|
| 22 | + pytest.param("2023/04/26 14-00-00", 1682517600), |
| 23 | + pytest.param("March 3, 2023", 1677801600), |
| 24 | + pytest.param("01/04/2023", 1672790400), |
21 | 25 | pytest.param("", None),
|
22 |
| - pytest.param( |
23 |
| - "2018-12-13 PST", None, marks=[pytest.mark.xfail(raises=ValueError, strict=True)] |
24 |
| - ), |
25 | 26 | ],
|
26 | 27 | )
|
27 | 28 | def test_date_to_timestamp(date, exp_ts):
|
28 | 29 | assert date_to_timestamp(date) == exp_ts
|
29 | 30 |
|
30 | 31 |
|
| 32 | +def test_date_to_timestamp_out_of_range(): |
| 33 | + invalid_date = "1682470412" |
| 34 | + with pytest.raises(ParserError, match=f"year {invalid_date} is out of range"): |
| 35 | + date_to_timestamp(invalid_date) |
| 36 | + |
| 37 | + |
| 38 | +@pytest.mark.parametrize( |
| 39 | + "date", |
| 40 | + [ |
| 41 | + pytest.param("2018-12-13 PST"), |
| 42 | + pytest.param("2023-04-26 14:30 PM"), |
| 43 | + ], |
| 44 | +) |
| 45 | +def test_date_to_timestamp_invalid(date): |
| 46 | + with pytest.raises(ValueError, match="Unknown string format"): |
| 47 | + date_to_timestamp(date) |
| 48 | + |
| 49 | + |
31 | 50 | def test_parse_date():
|
32 | 51 | # Test parsing an ISO8601 string
|
33 | 52 | expected = datetime.datetime(year=2020, month=1, day=1, tzinfo=datetime.timezone.utc)
|
|
0 commit comments