Skip to content

Commit 57e18e8

Browse files
committed
improved test_date_to_timestamp_* testing
1 parent e135038 commit 57e18e8

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

test/test_utilities.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from unittest import mock
88

99
import pytest
10+
from dateutil.parser import ParserError
1011

1112
from parsons import Table
1213
from parsons.utilities import check_env, files, json_format, sql_helpers
@@ -18,16 +19,34 @@
1819
[
1920
pytest.param("2018-12-13", 1544659200),
2021
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),
2125
pytest.param("", None),
22-
pytest.param(
23-
"2018-12-13 PST", None, marks=[pytest.mark.xfail(raises=ValueError, strict=True)]
24-
),
2526
],
2627
)
2728
def test_date_to_timestamp(date, exp_ts):
2829
assert date_to_timestamp(date) == exp_ts
2930

3031

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+
3150
def test_parse_date():
3251
# Test parsing an ISO8601 string
3352
expected = datetime.datetime(year=2020, month=1, day=1, tzinfo=datetime.timezone.utc)

0 commit comments

Comments
 (0)