Skip to content

Commit

Permalink
Add test case for getFeatures on invalid bad layer
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Nov 5, 2018
1 parent 4077104 commit 5010956
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/src/python/test_qgsprojectbadlayers.py
Expand Up @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit 5010956

Please sign in to comment.