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 20, 2019
1 parent e8a1b8a commit b8bb468
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 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)


class ParserTest(unittest.TestCase):
Expand Down

0 comments on commit b8bb468

Please sign in to comment.