Skip to content

Commit

Permalink
Use convenience function for testing tz object
Browse files Browse the repository at this point in the history
For all of these tests, the most important part of the test is ensuring
that the correct tzinfo object was attached, so it makes sense to add a
convenience function that asserts that they are identical *and* have the
same tzinfo object.
  • Loading branch information
pganssle committed Mar 19, 2019
1 parent 192d14a commit eaf0d4b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions dateutil/test/test_parser.py
Expand Up @@ -348,17 +348,21 @@ def test_parse_bytearray(self):


class TestTzinfoInputTypes(object):
def assert_equal_same_tz(self, dt1, dt2):
assert dt1 == dt2
assert dt1.tzinfo is dt2.tzinfo

def test_tzinfo_dict_could_return_none(self):
dstr = "2017-02-03 12:40 BRST"
result = parse(dstr, tzinfos={"BRST": None})
expected = datetime(2017, 2, 3, 12, 40)
assert result == expected
self.assert_equal_same_tz(result, expected)

def test_tzinfos_callable_could_return_none(self):
dstr = "2017-02-03 12:40 BRST"
result = parse(dstr, tzinfos=lambda *args: None)
expected = datetime(2017, 2, 3, 12, 40)
assert result == expected
self.assert_equal_same_tz(result, expected)

def test_invalid_tzinfo_input(self):
dstr = "2014 January 19 09:00 UTC"
Expand All @@ -372,15 +376,14 @@ def test_valid_tzinfo_tzinfo_input(self):
tzinfos = {"UTC": tz.UTC}
expected = datetime(2014, 1, 19, 9, tzinfo=tz.UTC)
res = parse(dstr, tzinfos=tzinfos)
assert res == expected
assert res.tzinfo is expected.tzinfo
self.assert_equal_same_tz(res, expected)

def test_valid_tzinfo_unicode_input(self):
dstr = "2014 January 19 09:00 UTC"
tzinfos = {u"UTC": u"UTC+0"}
expected = datetime(2014, 1, 19, 9, tzinfo=tz.UTC)
expected = datetime(2014, 1, 19, 9, tzinfo=tz.tzstr("UTC+0"))
res = parse(dstr, tzinfos=tzinfos)
assert res == expected
self.assert_equal_same_tz(res, expected)

def test_valid_tzinfo_callable_input(self):
dstr = "2014 January 19 09:00 UTC"
Expand All @@ -390,8 +393,7 @@ def tzinfos(*args, **kwargs):

expected = datetime(2014, 1, 19, 9, tzinfo=tz.tzstr("UTC+0"))
res = parse(dstr, tzinfos=tzinfos)
assert res == expected
assert res.tzinfo is expected.tzinfo
self.assert_equal_same_tz(res, expected)

@pytest.mark.xfail(reason="Doesn't check for UTC in tzinfos dict, "
"not sure it *should*.")
Expand All @@ -400,8 +402,7 @@ def test_valid_tzinfo_int_input(self):
tzinfos = {u"UTC": -28800}
expected = datetime(2014, 1, 19, 9, tzinfo=tz.UTC)
res = parse(dstr, tzinfos=tzinfos)
assert res == expected
assert res.tzinfo is expected.tzinfo
self.assert_equal_same_tz(res, expected)


class ParserTest(unittest.TestCase):
Expand Down

0 comments on commit eaf0d4b

Please sign in to comment.