Skip to content

Commit a72690b

Browse files
anmyachevvnlitvinov
authored andcommitted
first attemp to use hypothesis in tests
1 parent 76bd004 commit a72690b

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

pandas/tests/io/parser/test_parse_dates.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"""
77

88
from datetime import date, datetime
9+
from dateutil.parser import parse as du_parse
10+
11+
from hypothesis import given, strategies as st
12+
913
from io import StringIO
1014

1115
from dateutil.parser import parse
@@ -15,7 +19,8 @@
1519

1620
from pandas._libs.tslib import Timestamp
1721
from pandas._libs.tslibs import parsing
18-
from pandas.compat import lrange
22+
from pandas._libs.tslibs.parsing import parse_datetime_string
23+
from pandas.compat import lrange, parse_date
1924
from pandas.compat.numpy import np_array_datetime64_compat
2025

2126
import pandas as pd
@@ -897,3 +902,30 @@ def test_parse_delimited_date_swap(all_parsers, datestring,
897902
result = parser.read_csv(StringIO(datestring), header=None,
898903
dayfirst=dayfirst, parse_dates=[0])
899904
tm.assert_frame_equal(result, expected)
905+
906+
907+
gen_random_datetime = st.dates(
908+
min_value=date(1000, 1, 1),
909+
max_value=date(9999, 12, 31)
910+
)
911+
_DEFAULT_DATETIME = datetime(1, 1, 1).replace(hour=0, minute=0,
912+
second=0, microsecond=0)
913+
914+
915+
@given(gen_random_datetime)
916+
@pytest.mark.parametrize("date_format, delimiters, dayfirst", [
917+
("%m %d %Y", " -./", False),
918+
("%m %d %Y", " -./", True),
919+
("%d %m %Y", " -./", True),
920+
("%d %m %Y", " -./", False),
921+
("%m %Y", " -/", False),
922+
("%m %Y", " -/", True)
923+
])
924+
def test_hypothesis_delimited_date(date_format, delimiters, dayfirst, date):
925+
date_strings = [date.strftime(date_format.replace(' ', delim))
926+
for delim in delimiters]
927+
for date_string in date_strings:
928+
result = parse_datetime_string(date_string, dayfirst=dayfirst)
929+
expected = du_parse(date_string, default=_DEFAULT_DATETIME,
930+
dayfirst=dayfirst, yearfirst=False)
931+
assert result == expected

0 commit comments

Comments
 (0)