Skip to content
Browse files
Add unit test for f947ffb
  • Loading branch information
nyalldawson committed Apr 18, 2019
1 parent c1a76c4 commit 5456f1d9542cb9a9abba61c6a15d549f38bfdb0c
Showing 1 changed file with 35 additions and 0 deletions.
@@ -357,6 +357,41 @@ def testSetDataSource(self):
self.assertNotEqual(layer.renderer(), r)
self.assertEqual(layer.renderer().symbol().type(), QgsSymbol.Line)

def testSetDataSourceInvalidToValid(self):
Test that changing an invalid layer path to valid maintains the renderer
layer = createLayerWithOnePoint()
r = QgsSingleSymbolRenderer(QgsSymbol.defaultSymbol(QgsWkbTypes.PointGeometry))
self.assertEqual(layer.renderer().symbol().type(), QgsSymbol.Marker)

# change to invalid path
options = QgsDataProvider.ProviderOptions()
layer.setDataSource('nothing', 'new name', 'ogr', options)

# these properties should be kept intact!
self.assertEqual(, 'new name')
self.assertEqual(layer.wkbType(), QgsWkbTypes.Point)
self.assertEqual(, 'EPSG:3111')
# should have kept the same renderer!
self.assertEqual(layer.renderer(), r)

# set to a valid path
points_path = os.path.join(unitTestDataPath(), 'points.shp')
layer.setDataSource(points_path, 'new name2', 'ogr', options)

self.assertEqual(, 'new name2')
self.assertEqual(layer.wkbType(), QgsWkbTypes.Point)
self.assertEqual(, 'EPSG:4326')
self.assertIn(points_path, layer.dataProvider().dataSourceUri())

# should STILL have kept renderer!
self.assertEqual(layer.renderer(), r)

def test_layer_crs(self):
Test that spatial layers have CRS, and non-spatial don't

0 comments on commit 5456f1d

Please sign in to comment.