Skip to content
Permalink
Browse files

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 922bf86bd2d9e24f16af3e17bbee0d5584c2ef60
Showing with 3 additions and 3 deletions.
  1. +3 −3 tests/src/python/test_provider_postgres.py
@@ -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.
@@ -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")
@@ -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

0 comments on commit 922bf86

Please sign in to comment.
You can’t perform that action at this time.