Skip to content

Commit

Permalink
add test for microsecond
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuehlbauer committed Dec 14, 2024
1 parent d9699e7 commit 566c08a
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions xarray/tests/test_cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ def date_dict(
year="1999", month="01", day="01", hour="12", minute="34", second="56"
),
),
"microsecond-1": (
"19990101T123456.123456",
date_dict(
year="1999",
month="01",
day="01",
hour="12",
minute="34",
second="56",
microsecond="123456",
),
),
"microsecond-2": (
"19990101T123456.1",
date_dict(
year="1999",
month="01",
day="01",
hour="12",
minute="34",
second="56",
microsecond="1",
),
),
}


Expand All @@ -112,8 +136,9 @@ def test_parse_iso8601_like(string, expected):
result = parse_iso8601_like(string)
assert result == expected

with pytest.raises(ValueError):
parse_iso8601_like(string + "3")
if result["microsecond"] is None:
with pytest.raises(ValueError):
parse_iso8601_like(string + "3")
if result["second"] is None:
with pytest.raises(ValueError):
parse_iso8601_like(string + ".3")
Expand Down Expand Up @@ -317,6 +342,7 @@ def test_cftimeindex_days_in_month_accessor(index):
("19990202T01", (1999, 2, 2, 1), "hour"),
("19990202T0101", (1999, 2, 2, 1, 1), "minute"),
("19990202T010156", (1999, 2, 2, 1, 1, 56), "second"),
("19990202T010156.123456", (1999, 2, 2, 1, 1, 56, 123456), "microsecond"),
],
)
def test_parse_iso8601_with_reso(date_type, string, date_args, reso):
Expand Down

0 comments on commit 566c08a

Please sign in to comment.