pganssle / zoneinfo

Reference implementation for the proposed standard library module zoneinfo
Other
52 stars 20 forks source link

Test failures with timezone 2022a #114

Closed s-t-e-v-e-n-k closed 1 year ago

s-t-e-v-e-n-k commented 2 years ago

Upgrading an openSUSE system to the new 2022a release of timezone results in test failures, which I'm having a lot of trouble debugging:

=================================== FAILURES ===================================
_ ZoneInfoTest.test_unambiguous (dt=datetime.datetime(1889, 12, 30, 0, 0), key='America/Santiago', offset=ZoneOffset(tzname='LMT', utcoffset=datetime.timedelta(days=-1, seconds=69434), dst=datetime.timedelta(0))) _

self = <tests.test_zoneinfo.ZoneInfoTest testMethod=test_unambiguous>

    def test_unambiguous(self):
        test_cases = []
        for key in self.zones():
            for zone_transition in self.load_transition_examples(key):
                test_cases.append(
                    (
                        key,
                        zone_transition.transition - timedelta(days=2),
                        zone_transition.offset_before,
                    )
                )

                test_cases.append(
                    (
                        key,
                        zone_transition.transition + timedelta(days=2),
                        zone_transition.offset_after,
                    )
                )

        for key, dt, offset in test_cases:
            with self.subTest(key=key, dt=dt, offset=offset):
                tzi = self.zone_from_key(key)
                dt = dt.replace(tzinfo=tzi)

                self.assertEqual(dt.tzname(), offset.tzname, dt)
>               self.assertEqual(dt.utcoffset(), offset.utcoffset, dt)
E               AssertionError: datetime.timedelta(days=-1, seconds=69435) != datetime.timedelta(days=-1, seconds=69434) : 1889-12-30 00:00:00-04:42:45

tests/test_zoneinfo.py:311: AssertionError
_ ZoneInfoTest.test_unambiguous (dt=datetime.datetime(1890, 1, 3, 0, 0), key='America/Santiago', offset=ZoneOffset(tzname='SMT', utcoffset=datetime.timedelta(days=-1, seconds=69434), dst=datetime.timedelta(0))) _

self = <tests.test_zoneinfo.ZoneInfoTest testMethod=test_unambiguous>

    def test_unambiguous(self):
        test_cases = []
        for key in self.zones():
            for zone_transition in self.load_transition_examples(key):
                test_cases.append(
                    (
                        key,
                        zone_transition.transition - timedelta(days=2),
                        zone_transition.offset_before,
                    )
                )

                test_cases.append(
                    (
                        key,
                        zone_transition.transition + timedelta(days=2),
                        zone_transition.offset_after,
                    )
                )

        for key, dt, offset in test_cases:
            with self.subTest(key=key, dt=dt, offset=offset):
                tzi = self.zone_from_key(key)
                dt = dt.replace(tzinfo=tzi)

                self.assertEqual(dt.tzname(), offset.tzname, dt)
>               self.assertEqual(dt.utcoffset(), offset.utcoffset, dt)
E               AssertionError: datetime.timedelta(days=-1, seconds=69435) != datetime.timedelta(days=-1, seconds=69434) : 1890-01-03 00:00:00-04:42:45

tests/test_zoneinfo.py:311: AssertionError
_ ZoneInfoTest.test_unambiguous (dt=datetime.datetime(1910, 1, 8, 0, 0), key='America/Santiago', offset=ZoneOffset(tzname='SMT', utcoffset=datetime.timedelta(days=-1, seconds=69434), dst=datetime.timedelta(0))) _

self = <tests.test_zoneinfo.ZoneInfoTest testMethod=test_unambiguous>

    def test_unambiguous(self):
        test_cases = []
        for key in self.zones():
            for zone_transition in self.load_transition_examples(key):
                test_cases.append(
                    (
                        key,
                        zone_transition.transition - timedelta(days=2),
                        zone_transition.offset_before,
                    )
                )

                test_cases.append(
                    (
                        key,
                        zone_transition.transition + timedelta(days=2),
                        zone_transition.offset_after,
                    )
                )

        for key, dt, offset in test_cases:
            with self.subTest(key=key, dt=dt, offset=offset):
                tzi = self.zone_from_key(key)
                dt = dt.replace(tzinfo=tzi)

                self.assertEqual(dt.tzname(), offset.tzname, dt)
>               self.assertEqual(dt.utcoffset(), offset.utcoffset, dt)
E               AssertionError: datetime.timedelta(days=-1, seconds=69435) != datetime.timedelta(days=-1, seconds=69434) : 1910-01-08 00:00:00-04:42:45

tests/test_zoneinfo.py:311: AssertionError
_ ZoneInfoTest.test_unambiguous (dt=datetime.datetime(1916, 7, 3, 0, 0), key='America/Santiago', offset=ZoneOffset(tzname='SMT', utcoffset=datetime.timedelta(days=-1, seconds=69434), dst=datetime.timedelta(0))) _

self = <tests.test_zoneinfo.ZoneInfoTest testMethod=test_unambiguous>

    def test_unambiguous(self):
        test_cases = []
        for key in self.zones():
            for zone_transition in self.load_transition_examples(key):
                test_cases.append(
                    (
                        key,
                        zone_transition.transition - timedelta(days=2),
                        zone_transition.offset_before,
                    )
                )

                test_cases.append(
                    (
                        key,
                        zone_transition.transition + timedelta(days=2),
                        zone_transition.offset_after,
                    )
                )

        for key, dt, offset in test_cases:
            with self.subTest(key=key, dt=dt, offset=offset):
                tzi = self.zone_from_key(key)
                dt = dt.replace(tzinfo=tzi)

                self.assertEqual(dt.tzname(), offset.tzname, dt)
>               self.assertEqual(dt.utcoffset(), offset.utcoffset, dt)
E               AssertionError: datetime.timedelta(days=-1, seconds=69435) != datetime.timedelta(days=-1, seconds=69434) : 1916-07-03 00:00:00-04:42:45

tests/test_zoneinfo.py:311: AssertionError

I'm not certain where that loss of one second is coming from.

bnavigator commented 2 years ago

The tests expect information from timezone 2021a, but 2022a has updated the database for America/Santiago:

https://github.com/eggert/tz/compare/2021a...2022a (https://github.com/eggert/tz/commit/e8681e760f644c6c04d1bfef98123d1b47156e54)