-
Notifications
You must be signed in to change notification settings - Fork 679
/
Copy pathtest_utils.py
46 lines (37 loc) · 1.47 KB
/
test_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import datetime as dt
import pandas as pd
import pytest
from pandas_datareader._utils import _sanitize_dates
class TestUtils:
@pytest.mark.parametrize(
"input_date",
[
"2019-01-01",
"JAN-01-2010",
dt.datetime(2019, 1, 1),
dt.date(2019, 1, 1),
pd.Timestamp(2019, 1, 1),
],
)
def test_sanitize_dates(self, input_date):
expected_start = pd.to_datetime(input_date)
expected_end = pd.to_datetime(dt.date.today())
result = _sanitize_dates(input_date, None)
assert result == (expected_start, expected_end)
def test_sanitize_dates_int(self):
start_int = 2018
end_int = 2019
expected_start = pd.to_datetime(dt.datetime(start_int, 1, 1))
expected_end = pd.to_datetime(dt.datetime(end_int, 1, 1))
assert _sanitize_dates(start_int, end_int) == (expected_start, expected_end)
def test_sanitize_invalid_dates(self):
with pytest.raises(ValueError):
_sanitize_dates(2019, 2018)
with pytest.raises(ValueError):
_sanitize_dates("2019-01-01", "2018-01-01")
with pytest.raises(ValueError):
_sanitize_dates("20199", None)
def test_sanitize_dates_defaults(self):
default_start = pd.to_datetime(dt.date.today() - dt.timedelta(days=365 * 5))
default_end = pd.to_datetime(dt.date.today())
assert _sanitize_dates(None, None) == (default_start, default_end)