Skip to content

Commit

Permalink
Test date tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ghickman committed Nov 16, 2023
1 parent 2a1071b commit 27833ea
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Empty file added tests/metrics/__init__.py
Empty file.
Empty file added tests/metrics/tools/__init__.py
Empty file.
50 changes: 50 additions & 0 deletions tests/metrics/tools/test_dates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from datetime import date, datetime

import pytest

from metrics.tools.dates import date_from_iso, datetime_from_iso, iter_days


@pytest.mark.parametrize(
"value,expected",
[
(None, None),
("2020-07-08", date(2020, 7, 8)),
("2020-07-08T09:12", date(2020, 7, 8)),
],
)
def test_date_from_iso(value, expected):
assert date_from_iso(value) == expected


@pytest.mark.parametrize(
"value,expected",
[
(None, None),
("2020-07-08", datetime(2020, 7, 8, 0, 0, 0)),
("2020-07-08T09:12", datetime(2020, 7, 8, 9, 12, 0)),
],
)
def test_datetime_from_iso(value, expected):
assert datetime_from_iso(value) == expected


def test_iter_days():
dates = list(iter_days(date(2020, 7, 8), date(2020, 7, 10)))

assert dates == [
date(2020, 7, 8),
date(2020, 7, 9),
date(2020, 7, 10),
]


def test_iter_days_with_empty_values():
with pytest.raises(TypeError):
list(iter_days(None, date(2020, 7, 8)))

with pytest.raises(TypeError):
list(iter_days(date(2020, 7, 8), None))

with pytest.raises(TypeError):
list(iter_days(date(2020, 7, 8), date(2022, 7, 8), None))

0 comments on commit 27833ea

Please sign in to comment.