Skip to content

Commit

Permalink
Adding test for curve geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
szekerest authored and nyalldawson committed Jun 15, 2019
1 parent 2dc40ae commit 7d1b0cb
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions tests/src/python/test_provider_mssql.py
Expand Up @@ -58,10 +58,16 @@ def setUpClass(cls):

cls.conn = QSqlDatabase.addDatabase('QODBC')
cls.conn.setDatabaseName('testsqlserver')
if 'QGIS_MSSQLTEST_DB' in os.environ:
cls.conn.setDatabaseName('QGIS_MSSQLTEST_DB')
cls.conn.setUserName('SA')
cls.conn.setPassword('<YourStrong!Passw0rd>')
if 'QGIS_MSSQLTEST_DB2' in os.environ:
print(os.environ['QGIS_MSSQLTEST_DB2'])
cls.conn.setDatabaseName(os.environ['QGIS_MSSQLTEST_DB2'])
elif 'QGIS_MSSQLTEST_DB' in os.environ:
print(os.environ['QGIS_MSSQLTEST_DB'])
cls.conn.setDatabaseName(os.environ['QGIS_MSSQLTEST_DB'])
else:
cls.conn.setUserName('SA')
cls.conn.setPassword('<YourStrong!Passw0rd>')

assert cls.conn.open(), cls.conn.lastError().text()

# Triggers a segfault in the sql server odbc driver on Travis - TODO test with more recent Ubuntu base image
Expand Down Expand Up @@ -351,6 +357,28 @@ def testCreateLayerMultiPoint(self):
geom = [f.geometry().asWkt() for f in new_layer.getFeatures()]
self.assertEqual(geom, ['MultiPoint ((1 2),(3 4))', '', 'MultiPoint ((7 8))'])

@unittest.skipIf(os.environ.get('TRAVIS', '') == 'true', 'Failing on Travis')
def testCurveGeometries(self):
geomtypes = ['CompoundCurve', 'CurvePolygon', 'CircularString']
geoms = ['CompoundCurve ((0 -23.43778, 0 23.43778),CircularString (0 23.43778, -45 33.43778, -90 23.43778),(-90 23.43778, -90 -23.43778),CircularString (-90 -23.43778, -45 -23.43778, 0 -23.43778))', 'CurvePolygon (CompoundCurve ((0 -23.43778, 0 -15.43778, 0 23.43778),CircularString (0 23.43778, -45 100, -90 23.43778),(-90 23.43778, -90 -23.43778),CircularString (-90 -23.43778, -45 -16.43778, 0 -23.43778)),CompoundCurve (CircularString (-30 0, -48 -12, -60 0, -48 -6, -30 0)))', 'CircularString (0 0, 0.14644660940672 0.35355339059327, 0.5 0.5, 0.85355339059327 0.35355339059327, 1 0, 0.85355339059327 -0.35355339059327, 0.5 -0.5, 0.14644660940672 -0.35355339059327, 0 0)']
for idx, t in enumerate(geoms):
f = QgsFeature()
g = QgsGeometry.fromWkt(t)
f.setGeometry(g)
layer = QgsVectorLayer(geomtypes[idx] + "?crs=epsg:4326", "addfeat", "memory")
pr = layer.dataProvider()
pr.addFeatures([f])
uri = self.dbconn + ' table="qgis_test"."new_table_curvegeom_' + str(idx) + '" sql='
error, message = QgsVectorLayerExporter.exportLayer(layer, uri, 'mssql', QgsCoordinateReferenceSystem('EPSG:4326'))
self.assertEqual(error, QgsVectorLayerExporter.NoError)
new_layer = QgsVectorLayer(uri, 'new', 'mssql')
self.assertTrue(new_layer.isValid())
self.assertEqual(new_layer.wkbType(), g.wkbType())
self.assertEqual(new_layer.crs().authid(), 'EPSG:4326')
result_geoms = [f.geometry().asWkt(14) for f in new_layer.getFeatures()]
self.assertEqual(result_geoms, [t])
self.execSQLCommand('DROP TABLE IF EXISTS [qgis_test].[new_table_curvegeom_{}]'.format(str(idx)))

def testInsertPolygonInMultiPolygon(self):
layer = QgsVectorLayer("MultiPolygon?crs=epsg:4326&field=id:integer", "addfeat", "memory")
pr = layer.dataProvider()
Expand Down

0 comments on commit 7d1b0cb

Please sign in to comment.