diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-03-17 22:28:00 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-03-17 22:39:34 +0300 |
commit | dfe0e4b5acdf479f3e41e710c58218b6baf04f0e (patch) | |
tree | 8759ce1beac8d933782615b0209e78577b51eaed /contrib/python/python-dateutil/py3/tests/property | |
parent | a6dc0df43db569e4122947dbfeb7d013432300d4 (diff) | |
download | ydb-dfe0e4b5acdf479f3e41e710c58218b6baf04f0e.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/python/python-dateutil/py3/tests/property')
3 files changed, 84 insertions, 0 deletions
diff --git a/contrib/python/python-dateutil/py3/tests/property/test_isoparse_prop.py b/contrib/python/python-dateutil/py3/tests/property/test_isoparse_prop.py new file mode 100644 index 0000000000..f8e288f3d6 --- /dev/null +++ b/contrib/python/python-dateutil/py3/tests/property/test_isoparse_prop.py @@ -0,0 +1,27 @@ +from hypothesis import given, assume +from hypothesis import strategies as st + +from dateutil import tz +from dateutil.parser import isoparse + +import pytest + +# Strategies +TIME_ZONE_STRATEGY = st.sampled_from([None, tz.UTC] + + [tz.gettz(zname) for zname in ('US/Eastern', 'US/Pacific', + 'Australia/Sydney', 'Europe/London')]) +ASCII_STRATEGY = st.characters(max_codepoint=127) + + +@pytest.mark.isoparser +@given(dt=st.datetimes(timezones=TIME_ZONE_STRATEGY), sep=ASCII_STRATEGY) +def test_timespec_auto(dt, sep): + if dt.tzinfo is not None: + # Assume offset has no sub-second components + assume(dt.utcoffset().total_seconds() % 60 == 0) + + sep = str(sep) # Python 2.7 requires bytes + dtstr = dt.isoformat(sep=sep) + dt_rt = isoparse(dtstr) + + assert dt_rt == dt diff --git a/contrib/python/python-dateutil/py3/tests/property/test_parser_prop.py b/contrib/python/python-dateutil/py3/tests/property/test_parser_prop.py new file mode 100644 index 0000000000..fdfd171e86 --- /dev/null +++ b/contrib/python/python-dateutil/py3/tests/property/test_parser_prop.py @@ -0,0 +1,22 @@ +from hypothesis.strategies import integers +from hypothesis import given + +import pytest + +from dateutil.parser import parserinfo + + +@pytest.mark.parserinfo +@given(integers(min_value=100, max_value=9999)) +def test_convertyear(n): + assert n == parserinfo().convertyear(n) + + +@pytest.mark.parserinfo +@given(integers(min_value=-50, + max_value=49)) +def test_convertyear_no_specified_century(n): + p = parserinfo() + new_year = p._year + n + result = p.convertyear(new_year % 100, century_specified=False) + assert result == new_year diff --git a/contrib/python/python-dateutil/py3/tests/property/test_tz_prop.py b/contrib/python/python-dateutil/py3/tests/property/test_tz_prop.py new file mode 100644 index 0000000000..ec6d271dcf --- /dev/null +++ b/contrib/python/python-dateutil/py3/tests/property/test_tz_prop.py @@ -0,0 +1,35 @@ +from datetime import datetime, timedelta + +import pytest +import six +from hypothesis import assume, given +from hypothesis import strategies as st + +from dateutil import tz as tz + +EPOCHALYPSE = datetime.fromtimestamp(2147483647) +NEGATIVE_EPOCHALYPSE = datetime.fromtimestamp(0) - timedelta(seconds=2147483648) + + +@pytest.mark.gettz +@pytest.mark.parametrize("gettz_arg", [None, ""]) +# TODO: Remove bounds when GH #590 is resolved +@given( + dt=st.datetimes( + min_value=NEGATIVE_EPOCHALYPSE, max_value=EPOCHALYPSE, timezones=st.just(tz.UTC), + ) +) +def test_gettz_returns_local(gettz_arg, dt): + act_tz = tz.gettz(gettz_arg) + if isinstance(act_tz, tz.tzlocal): + return + + dt_act = dt.astimezone(tz.gettz(gettz_arg)) + if six.PY2: + dt_exp = dt.astimezone(tz.tzlocal()) + else: + dt_exp = dt.astimezone() + + assert dt_act == dt_exp + assert dt_act.tzname() == dt_exp.tzname() + assert dt_act.utcoffset() == dt_exp.utcoffset() |