From eaf0d4b95c05b8537e15ba152e32a72f69742393 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Tue, 19 Mar 2019 09:40:10 -0400 Subject: [PATCH] Use convenience function for testing tz object 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. --- dateutil/test/test_parser.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/dateutil/test/test_parser.py b/dateutil/test/test_parser.py index 0278c942c..6321f4c54 100644 --- a/dateutil/test/test_parser.py +++ b/dateutil/test/test_parser.py @@ -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" @@ -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" @@ -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*.") @@ -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):