Skip to content

Commit

Permalink
More readable test
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Nov 5, 2018
1 parent 5010956 commit 99638cf
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/src/python/test_qgsprojectbadlayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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__':
Expand Down

0 comments on commit 99638cf

Please sign in to comment.