]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Fix rounding error in float comparison tests with postgres < 12
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 23 Jun 2021 12:10:57 +0000 (13:10 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 25 Jun 2021 15:16:26 +0000 (16:16 +0100)
tests/fix_faker.py

index 9c20e3689ce2cf0b111ba2cd57bb0aed638925bd..e10b02730994725123f620df4671270b769f46ec 100644 (file)
@@ -318,7 +318,13 @@ class Faker:
         if got is not None and isnan(got):
             assert isnan(want)
         else:
-            assert got == want
+            # Versions older than 12 make some rounding. e.g. in Postgres 10.4
+            # select '-1.409006204063909e+112'::float8
+            #      -> -1.40900620406391e+112
+            if self.conn.info.server_version >= 120000:
+                assert got == want
+            else:
+                assert got == pytest.approx(want)
 
     def make_int(self, spec):
         return randrange(-(1 << 90), 1 << 90)