Skip to content

Commit f695ffc

Browse files
committed
improved test_date_to_timestamp_* testing
1 parent cbeeef5 commit f695ffc

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

test/test_azure/test_azure_blob_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from urllib.parse import parse_qs, urlparse
55

66
from azure.storage.blob import BlobClient, ContainerClient
7-
from test.utils import mark_live_test
87

98
from parsons import AzureBlobStorage, Table
109
from parsons.utilities import files
10+
from test.utils import mark_live_test
1111

1212
TEST_ACCOUNT_NAME = os.getenv("PARSONS_AZURE_ACCOUNT_NAME")
1313
TEST_CREDENTIAL = os.getenv("PARSONS_AZURE_CREDENTIAL")

test/test_box/test_box_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import pytest
99
from boxsdk.exception import BoxAPIException, BoxOAuthException
10-
from test.utils import mark_live_test
1110

1211
from parsons import Box, Table
12+
from test.utils import mark_live_test
1313

1414
"""Prior to running, you should ensure that the relevant environment
1515
variables have been set, e.g. via

test/test_civis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import unittest
22

3-
from test.utils import mark_live_test
4-
53
from parsons import CivisClient, Table
4+
from test.utils import mark_live_test
65

76
# from . import scratch_creds
87

test/test_facebook_ads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import unittest
22

33
import pytest
4-
from test.utils import mark_live_test
54

65
from parsons import FacebookAds, Table
6+
from test.utils import mark_live_test
77

88
users_table = Table(
99
[

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)