Skip to content
Permalink
Browse files

Add unit test for f947ffb

  • Loading branch information
nyalldawson committed Apr 18, 2019
1 parent f742044 commit 786929b4eac27bb15f18719a32ab9e9306156b50
Showing with 35 additions and 0 deletions.
  1. +35 −0 tests/src/python/test_qgsvectorlayer.py
@@ -358,6 +358,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()
layer.setCrs(QgsCoordinateReferenceSystem("epsg:3111"))
r = QgsSingleSymbolRenderer(QgsSymbol.defaultSymbol(QgsWkbTypes.PointGeometry))
layer.setRenderer(r)
self.assertEqual(layer.renderer().symbol().type(), QgsSymbol.Marker)

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

self.assertFalse(layer.isValid())
# these properties should be kept intact!
self.assertEqual(layer.name(), 'new name')
self.assertEqual(layer.wkbType(), QgsWkbTypes.Point)
self.assertEqual(layer.crs().authid(), '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.assertTrue(layer.isValid())
self.assertEqual(layer.name(), 'new name2')
self.assertEqual(layer.wkbType(), QgsWkbTypes.Point)
self.assertEqual(layer.crs().authid(), '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 786929b

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