From 167bcf03eebf98761f70e7fcadc1ba6f3843b174 Mon Sep 17 00:00:00 2001 From: Daniel Lemm <61800298+ffe4@users.noreply.github.com> Date: Sat, 4 Apr 2020 23:02:13 +0200 Subject: [PATCH] Update gettz tests Added test for gettz returning local when passed None or empty string. --- dateutil/test/test_tz.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/dateutil/test/test_tz.py b/dateutil/test/test_tz.py index 5fa2628c2..dc275a0fc 100644 --- a/dateutil/test/test_tz.py +++ b/dateutil/test/test_tz.py @@ -19,6 +19,9 @@ from functools import partial +from hypothesis import given +from hypothesis import strategies as st + IS_WIN = sys.platform.startswith('win') import pytest @@ -1077,12 +1080,28 @@ def testGettzCacheTzLocal(self): local2 = tz.gettz() assert local1 is not local2 - - def test_gettz_same_result_for_none_and_empty_string(self): - local1 = tz.gettz() - local2 = tz.gettz("") - assert local1 == local2 + +@pytest.mark.gettz +def test_gettz_same_result_for_none_and_empty_string(): + local_from_none = tz.gettz() + local_from_empty_string = tz.gettz("") + assert local_from_none is not None + assert local_from_empty_string is not None + assert local_from_none == local_from_empty_string + + +@pytest.mark.gettz +@pytest.mark.parametrize("gettz_arg", [None, ""]) # could add colon here +@given(dt=st.datetimes(max_value=datetime.now())) +def test_gettz_returns_local(gettz_arg, dt): + dt_act = dt.replace(tzinfo=tz.gettz()) + dt_exp = dt.replace(tzinfo=tz.tzlocal()) + + assert dt_act.tzname() == dt_exp.tzname() + assert dt_act.utcoffset() == dt_exp.utcoffset() + assert dt_act.dst() == dt_exp.dst() + assert dt_act == dt_exp @pytest.mark.gettz