Skip to content
Permalink
Browse files

More readable test

  • Loading branch information
elpaso committed Oct 29, 2018
1 parent 5010956 commit 99638cfdb6bf22b14a8a418c426bcf23e3e7e25c
Showing with 10 additions and 7 deletions.
  1. +10 −7 tests/src/python/test_qgsprojectbadlayers.py
@@ -46,7 +46,6 @@ 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')
@@ -66,11 +65,13 @@ def test_project_roundtrip(self):
# Load the bad project
self.assertTrue(p.read(bad_project_path))
# Check layer is invalid
invalid = list(p.mapLayersByName('lines'))[0]
self.assertFalse(invalid.isValid())
vector = list(p.mapLayersByName('lines'))[0]
raster = list(p.mapLayersByName('raster'))[0]
self.assertFalse(vector.isValid())
# Try a getFeatures
self.assertEqual([f for f in invalid.getFeatures()], [])
self.assertTrue(list(p.mapLayers().values())[1].isValid())
self.assertEqual([f for f in vector.getFeatures()], [])
self.assertTrue(raster.isValid())
self.assertEqual(vector.providerType(), 'ogr')

# Save the project
bad_project_path2 = os.path.join(temp_dir.path(), 'project_bad2.qgs')
@@ -84,8 +85,10 @@ def test_project_roundtrip(self):
# Load the good project
self.assertTrue(p.read(good_project_path))
# Check layer is valid
self.assertTrue(list(p.mapLayers().values())[0].isValid())
self.assertTrue(list(p.mapLayers().values())[1].isValid())
vector = list(p.mapLayersByName('lines'))[0]
raster = list(p.mapLayersByName('raster'))[0]
self.assertTrue(vector.isValid())
self.assertTrue(raster.isValid())


if __name__ == '__main__':

0 comments on commit 99638cf

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