Skip to content

Commit c1dbe64

Browse files
test: add parametrized tests for convert_partial_iso_format_to_full_iso_format
Covers abbreviated offsets (+00, -05), fractional seconds, full offsets, no-offset input, and date-only strings to prevent regressions. Co-Authored-By: Itamar Hartstein <haritamar@gmail.com>
1 parent b38a4b5 commit c1dbe64

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/unit/utils/test_time.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from datetime import datetime
22

3+
import pytest
34
from dateutil import tz
45

56
from elementary.utils.time import (
7+
convert_partial_iso_format_to_full_iso_format,
68
convert_time_to_timezone,
79
datetime_strftime,
810
get_formatted_timedelta,
@@ -67,3 +69,49 @@ def test_convert_time_to_timezone():
6769
assert date.hour == 1
6870
assert date_with_timezone.hour == 2
6971
assert (date - date_with_timezone).total_seconds() == 0
72+
73+
74+
@pytest.mark.parametrize(
75+
"input_time, expected_output",
76+
[
77+
pytest.param(
78+
"2024-01-01T12:00:00+00",
79+
"2024-01-01T12:00:00+00:00",
80+
id="abbreviated_utc_offset",
81+
),
82+
pytest.param(
83+
"2024-01-01T12:00:00-05",
84+
"2024-01-01T12:00:00-05:00",
85+
id="abbreviated_negative_offset",
86+
),
87+
pytest.param(
88+
"2024-01-01 12:00:00.123456+00",
89+
"2024-01-01T12:00:00+00:00",
90+
id="abbreviated_offset_with_fractional_seconds",
91+
),
92+
pytest.param(
93+
"2024-01-01T12:00:00+00:00",
94+
"2024-01-01T12:00:00+00:00",
95+
id="full_utc_offset",
96+
),
97+
pytest.param(
98+
"2024-01-01T12:00:00+05:30",
99+
"2024-01-01T12:00:00+05:30",
100+
id="full_non_utc_offset",
101+
),
102+
pytest.param(
103+
"2024-01-01T12:00:00",
104+
"2024-01-01T12:00:00+00:00",
105+
id="no_offset_defaults_to_utc",
106+
),
107+
pytest.param(
108+
"2024-01-15",
109+
"2024-01-15T00:00:00+00:00",
110+
id="date_only_not_corrupted",
111+
),
112+
],
113+
)
114+
def test_convert_partial_iso_format_to_full_iso_format(
115+
input_time: str, expected_output: str
116+
) -> None:
117+
assert convert_partial_iso_format_to_full_iso_format(input_time) == expected_output

0 commit comments

Comments
 (0)