Skip to content

Commit 12b1200

Browse files
committed
tests: add tests
Signed-off-by: Artem Inzhyyants <artem.inzhyyants@gmail.com>
1 parent 3a59755 commit 12b1200

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

unit_tests/sources/declarative/datetime/test_datetime_parser.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,102 +10,118 @@
1010

1111

1212
@pytest.mark.parametrize(
13-
"test_name, input_date, date_format, expected_output_date",
13+
"input_date, date_format, expected_output_date",
1414
[
1515
(
16-
"test_parse_date_iso",
1716
"2021-01-01T00:00:00.000000+0000",
1817
"%Y-%m-%dT%H:%M:%S.%f%z",
1918
datetime.datetime(2021, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
2019
),
2120
(
22-
"test_parse_date_iso_with_timezone_not_utc",
2321
"2021-01-01T00:00:00.000000+0400",
2422
"%Y-%m-%dT%H:%M:%S.%f%z",
2523
datetime.datetime(
2624
2021, 1, 1, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=14400))
2725
),
2826
),
2927
(
30-
"test_parse_timestamp",
3128
"1609459200",
3229
"%s",
3330
datetime.datetime(2021, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
3431
),
3532
(
36-
"test_parse_timestamp_as_float",
3733
"1675092508.873709",
3834
"%s_as_float",
3935
datetime.datetime(2023, 1, 30, 15, 28, 28, 873709, tzinfo=datetime.timezone.utc),
4036
),
4137
(
42-
"test_parse_ms_timestamp",
38+
"1675092508873709",
39+
"%epoch_microseconds",
40+
datetime.datetime(2023, 1, 30, 15, 28, 28, 873709, tzinfo=datetime.timezone.utc),
41+
),
42+
(
4343
"1609459200001",
4444
"%ms",
4545
datetime.datetime(2021, 1, 1, 0, 0, 0, 1000, tzinfo=datetime.timezone.utc),
4646
),
4747
(
48-
"test_parse_date_ms",
4948
"20210101",
5049
"%Y%m%d",
5150
datetime.datetime(2021, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
5251
),
5352
(
54-
"test_parse_format_datetime_with__ms",
5553
"2021-11-22T08:41:55.640Z",
5654
"%Y-%m-%dT%H:%M:%S.%_msZ",
5755
datetime.datetime(2021, 11, 22, 8, 41, 55, 640000, tzinfo=datetime.timezone.utc),
5856
),
5957
],
58+
ids=[
59+
"test_parse_date_iso",
60+
"test_parse_date_iso_with_timezone_not_utc",
61+
"test_parse_timestamp",
62+
"test_parse_timestamp_as_float",
63+
"test_parse_timestamp_microseconds",
64+
"test_parse_ms_timestamp",
65+
"test_parse_date_ms",
66+
"test_parse_format_datetime_with__ms",
67+
],
6068
)
61-
def test_parse_date(test_name, input_date, date_format, expected_output_date):
69+
def test_parse_date(input_date: str, date_format: str, expected_output_date: datetime.datetime):
6270
parser = DatetimeParser()
6371
output_date = parser.parse(input_date, date_format)
6472
assert output_date == expected_output_date
6573

6674

6775
@pytest.mark.parametrize(
68-
"test_name, input_dt, datetimeformat, expected_output",
76+
"input_dt, datetimeformat, expected_output",
6977
[
7078
(
71-
"test_format_timestamp",
7279
datetime.datetime(2021, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
7380
"%s",
7481
"1609459200",
7582
),
7683
(
77-
"test_format_timestamp_ms",
7884
datetime.datetime(2021, 1, 1, 0, 0, 0, 1000, tzinfo=datetime.timezone.utc),
7985
"%ms",
8086
"1609459200001",
8187
),
8288
(
83-
"test_format_timestamp_as_float",
8489
datetime.datetime(2023, 1, 30, 15, 28, 28, 873709, tzinfo=datetime.timezone.utc),
8590
"%s_as_float",
8691
"1675092508.873709",
8792
),
8893
(
89-
"test_format_string",
94+
datetime.datetime(2023, 1, 30, 15, 28, 28, 873709, tzinfo=datetime.timezone.utc),
95+
"%epoch_microseconds",
96+
"1675092508873709",
97+
),
98+
(
9099
datetime.datetime(2021, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
91100
"%Y-%m-%d",
92101
"2021-01-01",
93102
),
94103
(
95-
"test_format_to_number",
96104
datetime.datetime(2021, 1, 1, 0, 0, tzinfo=datetime.timezone.utc),
97105
"%Y%m%d",
98106
"20210101",
99107
),
100108
(
101-
"test_parse_format_datetime_with__ms",
102109
datetime.datetime(2021, 11, 22, 8, 41, 55, 640000, tzinfo=datetime.timezone.utc),
103110
"%Y-%m-%dT%H:%M:%S.%_msZ",
104111
"2021-11-22T08:41:55.640Z",
105112
),
106113
],
114+
ids=[
115+
"test_format_timestamp",
116+
"test_format_timestamp_ms",
117+
"test_format_timestamp_as_float",
118+
"test_format_timestamp_microseconds",
119+
"test_format_string",
120+
"test_format_to_number",
121+
"test_parse_format_datetime_with__ms",
122+
],
107123
)
108-
def test_format_datetime(test_name, input_dt, datetimeformat, expected_output):
124+
def test_format_datetime(input_dt: datetime.datetime, datetimeformat: str, expected_output: str):
109125
parser = DatetimeParser()
110126
output_date = parser.format(input_dt, datetimeformat)
111127
assert output_date == expected_output

0 commit comments

Comments
 (0)