PyFacts/tests/test_utils.py

27 lines
772 B
Python
Raw Normal View History

2022-03-30 17:36:45 +00:00
import datetime
import pytest
2022-06-05 17:42:04 +00:00
from pyfacts.utils import _interval_to_years, _parse_date
2022-03-30 17:36:45 +00:00
class TestParseDate:
def test_parsing(self):
dt = datetime.datetime(2020, 1, 1)
assert _parse_date(dt) == dt
assert _parse_date(dt.strftime("%Y-%m-%d")) == dt
assert _parse_date(datetime.date(2020, 1, 1)) == dt
assert _parse_date("01-01-2020", date_format="%d-%m-%Y") == dt
assert _parse_date("01-01-2020", date_format="%m-%d-%Y") == dt
def test_errors(self):
with pytest.raises(ValueError):
_parse_date("01-01-2020")
with pytest.raises(ValueError):
_parse_date("abcdefg")
class TestIntervalToYears:
def test_months(self):
assert _interval_to_years("months", 6) == 0.5