From: Dylan Young Date: Wed, 15 Jul 2026 01:22:06 +0000 (-0300) Subject: test: fix overflow in faker datetime handling X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7485979275db27adb68deceed7b0c99f2c1589cb;p=thirdparty%2Fpsycopg.git test: fix overflow in faker datetime handling Causes at least test_adapt::test_random to fail sometimes. --- diff --git a/tests/fix_faker.py b/tests/fix_faker.py index 905b6ad4a..cd6511f7d 100644 --- a/tests/fix_faker.py +++ b/tests/fix_faker.py @@ -334,10 +334,10 @@ class Faker: return self.schema_time(cls) def make_datetime(self, spec): - # Add a day because with timezone we might go BC + # Add/subtract a day because with timezone we might overflow dtmin = dt.datetime.min + dt.timedelta(days=1) - delta = dt.datetime.max - dtmin - micros = randrange((delta.days + 1) * 24 * 60 * 60 * 1_000_000) + delta = dt.datetime.max - dt.timedelta(days=1) - dtmin + micros = randrange(int(delta.total_seconds() * 1_000_000)) rv = dtmin + dt.timedelta(microseconds=micros) if spec[1]: rv = rv.replace(tzinfo=self._make_tz(spec))