|
14 | 14 | __revision__ = '$Format:%H$' |
15 | 15 |
|
16 | 16 | import qgis # NOQA |
| 17 | +import psycopg2 |
17 | 18 |
|
18 | 19 | import os |
19 | 20 |
|
20 | 21 | from qgis.core import ( |
| 22 | + QgsGeometry, |
| 23 | + QgsPoint, |
21 | 24 | QgsVectorLayer, |
| 25 | + QgsVectorLayerImport, |
22 | 26 | QgsFeatureRequest, |
23 | 27 | QgsFeature, |
24 | 28 | QgsTransactionGroup, |
@@ -50,11 +54,20 @@ def setUpClass(cls): |
50 | 54 | assert cls.poly_vl.isValid() |
51 | 55 | cls.poly_provider = cls.poly_vl.dataProvider() |
52 | 56 | QgsEditorWidgetRegistry.instance().initEditors() |
| 57 | + cls.con = psycopg2.connect(cls.dbconn) |
53 | 58 |
|
54 | 59 | @classmethod |
55 | 60 | def tearDownClass(cls): |
56 | 61 | """Run after all tests""" |
57 | 62 |
|
| 63 | + def execSQLCommand(self, sql): |
| 64 | + self.assertTrue(self.con) |
| 65 | + cur = self.con.cursor() |
| 66 | + self.assertTrue(cur) |
| 67 | + cur.execute(sql) |
| 68 | + cur.close() |
| 69 | + self.con.commit() |
| 70 | + |
58 | 71 | def enableCompiler(self): |
59 | 72 | QSettings().setValue('/qgis/compileExpressions', True) |
60 | 73 |
|
@@ -424,6 +437,30 @@ def testDoubleArray(self): |
424 | 437 | self.assertTrue(isinstance(f.attributes()[value_idx], list)) |
425 | 438 | self.assertEqual(f.attributes()[value_idx], [1.1, 2, -5.12345]) |
426 | 439 |
|
| 440 | + # See http://hub.qgis.org/issues/15188 |
| 441 | + def testNumericPrecision(self): |
| 442 | + uri = 'point?field=f1:int' |
| 443 | + uri += '&field=f2:double(6,4)' |
| 444 | + uri += '&field=f3:string(20)' |
| 445 | + lyr = QgsVectorLayer(uri, "x", "memory") |
| 446 | + self.assertTrue(lyr.isValid()) |
| 447 | + f = QgsFeature(lyr.fields()) |
| 448 | + f['f1'] = 1 |
| 449 | + f['f2'] = 123.456 |
| 450 | + f['f3'] = '12345678.90123456789' |
| 451 | + lyr.dataProvider().addFeatures([f]) |
| 452 | + uri = '%s table="qgis_test"."b18155" (g) key=\'f1\'' % (self.dbconn) |
| 453 | + self.execSQLCommand('DROP TABLE IF EXISTS qgis_test.b18155') |
| 454 | + err = QgsVectorLayerImport.importLayer(lyr, uri, "postgres", lyr.crs()) |
| 455 | + self.assertEqual(err[0], QgsVectorLayerImport.NoError, |
| 456 | + 'unexpected import error {0}'.format(err)) |
| 457 | + lyr = QgsVectorLayer(uri, "y", "postgres") |
| 458 | + self.assertTrue(lyr.isValid()) |
| 459 | + f = next(lyr.getFeatures()) |
| 460 | + self.assertEqual(f['f1'], 1) |
| 461 | + self.assertEqual(f['f2'], 123.456) |
| 462 | + self.assertEqual(f['f3'], '12345678.90123456789') |
| 463 | + |
427 | 464 |
|
428 | 465 | class TestPyQgsPostgresProviderCompoundKey(unittest.TestCase, ProviderTestCase): |
429 | 466 |
|
@@ -454,6 +491,5 @@ def uncompiledFilters(self): |
454 | 491 | def partiallyCompiledFilters(self): |
455 | 492 | return set([]) |
456 | 493 |
|
457 | | - |
458 | 494 | if __name__ == '__main__': |
459 | 495 | unittest.main() |
0 commit comments