Skip to content

Commit

Permalink
Update gettz tests
Browse files Browse the repository at this point in the history
Added test for gettz returning local when passed None, empty string or colon.
  • Loading branch information
ffe4 committed Apr 5, 2020
1 parent 96358e6 commit fa8e304
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions dateutil/test/test_tz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,12 +1077,32 @@ 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_equal_for_empty_string_and_none():
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
@pytest.mark.parametrize("dt", [
datetime(2018, 3, 10, tzinfo=tz.gettz("America/New_York")),
datetime(2018, 7, 13, tzinfo=tz.gettz("Europe/London")),
datetime(2019, 11, 18),
])
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
Expand Down

0 comments on commit fa8e304

Please sign in to comment.