Skip to content
Permalink
Browse files

Adjusting floating point comparisons in Python tests

Turns out that what passes on Python 3.8 and PostgreSQL 12 won't pass on
Python 3.7 and PostgreSQL 11 (Travis). So we round the floating point
comparisons to 5 digits in the testcases.
  • Loading branch information
espinafre authored and nyalldawson committed Jun 17, 2020
1 parent 44f4afe commit c521f39ef0c55370dcfa483f0049e1cb0ae7e83a
Showing with 11 additions and 4 deletions.
  1. +11 −4 tests/src/python/test_provider_postgres.py
@@ -786,7 +786,9 @@ def testPktComposite(self):
self.assertTrue(f.isValid())
self.assertEqual(f['pk1'], 1)
self.assertEqual(f['pk2'], 2)
self.assertEqual(f['pk3'], 3.1415927)

# round() needed to make sure Python older than 3.8 do the right thing.
self.assertEqual(round(f['pk3'], 5), round(3.1415927, 5))
self.assertEqual(f['value'], 'test 2')

# can we edit a field?
@@ -801,7 +803,8 @@ def testPktComposite(self):
self.assertTrue(f2.isValid())

# just making sure we have the correct feature
self.assertEqual(f2['pk3'], 3.1415927)
# round() needed to make sure Python older than 3.8 do the right thing.
self.assertEqual(round(f2['pk3'], 5), round(3.1415927, 5))

# Then, making sure we really did change our value.
self.assertEqual(f2['value'], 'Edited Test 2')
@@ -821,7 +824,9 @@ def testPktComposite(self):
f4 = next(vl2.getFeatures(QgsFeatureRequest().setFilterExpression('pk2 = -9223372036854775800')))

self.assertTrue(f4.isValid())
expected_attrs = [4, -9223372036854775800, 7.29154, 'other test']
# round() needed to make sure Python older than 3.8 do the right thing.
expected_attrs = [4, -9223372036854775800, round(7.29154, 5), 'other test']
gotten_attrs = [f4['pk1'], f4['pk2'], round(f4['pk3'], 5), f4['value']]
self.assertEqual(f4.attributes(), expected_attrs)

# Finally, let's delete one of the features.
@@ -851,7 +856,9 @@ def testPktFloat(self):
fields = vl.fields()
f = next(vl.getFeatures(QgsFeatureRequest().setFilterExpression('pk = 3.141592741')))
self.assertTrue(f.isValid())
self.assertEqual(f['pk'], 3.1415927)

# round() needed to make sure Python older than 3.8 do the right thing.
self.assertEqual(round(f['pk'], 5), round(3.1415927, 5))
self.assertEqual(f['value'], 'first test')

# editing

0 comments on commit c521f39

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