|
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,
|
@@ -48,11 +52,20 @@ def setUpClass(cls):
|
48 | 52 | cls.poly_vl = QgsVectorLayer(cls.dbconn + ' sslmode=disable key=\'pk\' srid=4326 type=POLYGON table="qgis_test"."some_poly_data" (geom) sql=', 'test', 'postgres')
|
49 | 53 | assert cls.poly_vl.isValid()
|
50 | 54 | cls.poly_provider = cls.poly_vl.dataProvider()
|
| 55 | + cls.con = psycopg2.connect(cls.dbconn) |
51 | 56 |
|
52 | 57 | @classmethod
|
53 | 58 | def tearDownClass(cls):
|
54 | 59 | """Run after all tests"""
|
55 | 60 |
|
| 61 | + def execSQLCommand(self, sql): |
| 62 | + self.assertTrue(self.con) |
| 63 | + cur = self.con.cursor() |
| 64 | + self.assertTrue(cur) |
| 65 | + cur.execute(sql) |
| 66 | + cur.close() |
| 67 | + self.con.commit() |
| 68 | + |
56 | 69 | def enableCompiler(self):
|
57 | 70 | QSettings().setValue(u'/qgis/compileExpressions', True)
|
58 | 71 |
|
@@ -312,5 +325,30 @@ def testRenameAttributes(self):
|
312 | 325 | self.assertEqual(fet.fields()[1].name(), 'newname2')
|
313 | 326 | self.assertEqual(fet.fields()[2].name(), 'another')
|
314 | 327 |
|
| 328 | + # See http://hub.qgis.org/issues/18155 |
| 329 | + def testNumericPrecision(self): |
| 330 | + uri = 'point?field=f1:int' |
| 331 | + uri += '&field=f2:double(6,4)' |
| 332 | + uri += '&field=f3:string(20)' |
| 333 | + lyr = QgsVectorLayer(uri, "x", "memory") |
| 334 | + self.assertTrue(lyr.isValid()) |
| 335 | + f = QgsFeature(lyr.fields()) |
| 336 | + f['f1'] = 1 |
| 337 | + f['f2'] = 123.456 |
| 338 | + f['f3'] = '12345678.90123456789' |
| 339 | + lyr.dataProvider().addFeatures([f]) |
| 340 | + uri = '%s table="qgis_test"."b18155" (g) key=\'f1\'' % (self.dbconn) |
| 341 | + self.execSQLCommand('DROP TABLE IF EXISTS qgis_test.b18155') |
| 342 | + err = QgsVectorLayerImport.importLayer(lyr, uri, "postgres", lyr.crs()) |
| 343 | + self.assertEqual(err[0], QgsVectorLayerImport.NoError, |
| 344 | + 'unexpected import error {0}'.format(err)) |
| 345 | + lyr = QgsVectorLayer(uri, "y", "postgres") |
| 346 | + self.assertTrue(lyr.isValid()) |
| 347 | + f = next(lyr.getFeatures()) |
| 348 | + self.assertEqual(f['f1'], 1) |
| 349 | + self.assertEqual(f['f2'], 123.456) |
| 350 | + self.assertEqual(f['f3'], '12345678.90123456789') |
| 351 | + |
| 352 | + |
315 | 353 | if __name__ == '__main__':
|
316 | 354 | unittest.main()
|
0 commit comments