Skip to content
Permalink
Browse files

Add test case for getFeatures on invalid bad layer

  • Loading branch information
elpaso committed Oct 29, 2018
1 parent 4077104 commit 5010956cb49b5ead63df29e5b5aaa2429493bec1
Showing with 6 additions and 1 deletion.
  1. +6 −1 tests/src/python/test_qgsprojectbadlayers.py
@@ -46,6 +46,7 @@ def test_project_roundtrip(self):
copyfile(os.path.join(TEST_DATA_DIR, 'lines.%s' % ext), os.path.join(temp_dir.path(), 'lines.%s' % ext))
copyfile(os.path.join(TEST_DATA_DIR, 'raster', 'band1_byte_ct_epsg4326.tif'), os.path.join(temp_dir.path(), 'band1_byte_ct_epsg4326.tif'))
l = QgsVectorLayer(os.path.join(temp_dir.path(), 'lines.shp'), 'lines', 'ogr')
wkb_type = l.wkbType()
self.assertTrue(l.isValid())

rl = QgsRasterLayer(os.path.join(temp_dir.path(), 'band1_byte_ct_epsg4326.tif'), 'raster', 'gdal')
@@ -65,8 +66,12 @@ def test_project_roundtrip(self):
# Load the bad project
self.assertTrue(p.read(bad_project_path))
# Check layer is invalid
self.assertFalse(list(p.mapLayers().values())[0].isValid())
invalid = list(p.mapLayersByName('lines'))[0]
self.assertFalse(invalid.isValid())
# Try a getFeatures
self.assertEqual([f for f in invalid.getFeatures()], [])
self.assertTrue(list(p.mapLayers().values())[1].isValid())

# Save the project
bad_project_path2 = os.path.join(temp_dir.path(), 'project_bad2.qgs')
p.write(bad_project_path2)

0 comments on commit 5010956

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