Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
round() on float equality comparisons in pgsql tests
We round floating point values in tests that check for equality between
two values in PostgreSQL tests, so that floating point implementation
differences in Python, PostgreSQL, GEOS etc. can be sorted out.
  • Loading branch information
espinafre authored and nyalldawson committed Dec 22, 2020
1 parent 5d65e3c commit 922bf86
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -554,7 +554,7 @@ def testGeneratedFields(self):
expected_area = 43069568296.34387

assert compareWkt(generated_geometry, expected_geometry), "Geometry mismatch! Expected:\n{}\nGot:\n{}\n".format(expected_geometry, generated_geometry)
self.assertEqual(f2['poly_area'], expected_area)
self.assertEqual(round(f2['poly_area'], 4), round(expected_area, 4))
self.assertEqual(f2['name'], 'QGIS-3')

# Checking if we can correctly change values of an existing feature.
Expand Down Expand Up @@ -582,7 +582,7 @@ def testGeneratedFields(self):
# reading back
vl2 = QgsVectorLayer('{} table="qgis_test"."{}" (geom) srid=4326 type=POLYGON key="id" sql='.format(self.dbconn, "test_gen_col"), "test_gen_col", "postgres")
f2 = next(vl2.getFeatures(QgsFeatureRequest()))
self.assertEqual(f2['poly_area'], expected_area)
self.assertEqual(round(f2['poly_area'], 4), round(expected_area, 4))

# now, getting a brand new QgsVectorLayer to check if changes (UPDATE) in the geometry are reflected in the generated fields
vl = QgsVectorLayer('{} table="qgis_test"."{}" (geom) srid=4326 type=POLYGON key="id" sql='.format(self.dbconn, "test_gen_col"), "test_gen_col", "postgres")
Expand All @@ -603,7 +603,7 @@ def testGeneratedFields(self):
expected_area = 67718478405.28429

assert compareWkt(generated_geometry, expected_geometry), "Geometry mismatch! Expected:\n{}\nGot:\n{}\n".format(expected_geometry, generated_geometry)
self.assertEqual(f2['poly_area'], expected_area)
self.assertEqual(round(f2['poly_area'], 4), round(expected_area, 4))
self.assertEqual(f2['name'], 'New')

# Geography columns
Expand Down

0 comments on commit 922bf86

Please sign in to comment.