Skip to content

Commit 9cfb436

Browse files
committedNov 5, 2018
Tests for bad layers raster support
1 parent 2af5fd1 commit 9cfb436

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed
 

‎tests/src/python/test_qgsprojectbadlayers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ def test_project_roundtrip(self):
4545
for ext in ('shp', 'dbf', 'shx', 'prj'):
4646
copyfile(os.path.join(TEST_DATA_DIR, 'lines.%s' % ext), os.path.join(temp_dir.path(), 'lines.%s' % ext))
4747
copyfile(os.path.join(TEST_DATA_DIR, 'raster', 'band1_byte_ct_epsg4326.tif'), os.path.join(temp_dir.path(), 'band1_byte_ct_epsg4326.tif'))
48+
copyfile(os.path.join(TEST_DATA_DIR, 'raster', 'band1_byte_ct_epsg4326.tif'), os.path.join(temp_dir.path(), 'band1_byte_ct_epsg4326_copy.tif'))
4849
l = QgsVectorLayer(os.path.join(temp_dir.path(), 'lines.shp'), 'lines', 'ogr')
4950
self.assertTrue(l.isValid())
5051

5152
rl = QgsRasterLayer(os.path.join(temp_dir.path(), 'band1_byte_ct_epsg4326.tif'), 'raster', 'gdal')
5253
self.assertTrue(rl.isValid())
53-
self.assertTrue(p.addMapLayers([l, rl]))
54+
rl_copy = QgsRasterLayer(os.path.join(temp_dir.path(), 'band1_byte_ct_epsg4326_copy.tif'), 'raster_copy', 'gdal')
55+
self.assertTrue(rl_copy.isValid())
56+
self.assertTrue(p.addMapLayers([l, rl, rl_copy]))
5457

5558
# Save project
5659
project_path = os.path.join(temp_dir.path(), 'project.qgs')
@@ -60,14 +63,19 @@ def test_project_roundtrip(self):
6063
bad_project_path = os.path.join(temp_dir.path(), 'project_bad.qgs')
6164
with open(project_path, 'r') as infile:
6265
with open(bad_project_path, 'w+') as outfile:
63-
outfile.write(infile.read().replace('./lines.shp', './lines-BAD_SOURCE.shp'))
66+
outfile.write(infile.read().replace('./lines.shp', './lines-BAD_SOURCE.shp').replace('band1_byte_ct_epsg4326_copy.tif', 'band1_byte_ct_epsg4326_copy-BAD_SOURCE.tif'))
6467

6568
# Load the bad project
6669
self.assertTrue(p.read(bad_project_path))
6770
# Check layer is invalid
6871
vector = list(p.mapLayersByName('lines'))[0]
6972
raster = list(p.mapLayersByName('raster'))[0]
73+
raster_copy = list(p.mapLayersByName('raster_copy'))[0]
74+
self.assertIsNotNone(vector.dataProvider())
75+
self.assertIsNotNone(raster.dataProvider())
76+
self.assertIsNotNone(raster_copy.dataProvider())
7077
self.assertFalse(vector.isValid())
78+
self.assertFalse(raster_copy.isValid())
7179
# Try a getFeatures
7280
self.assertEqual([f for f in vector.getFeatures()], [])
7381
self.assertTrue(raster.isValid())
@@ -80,15 +88,17 @@ def test_project_roundtrip(self):
8088
good_project_path = os.path.join(temp_dir.path(), 'project_good.qgs')
8189
with open(bad_project_path2, 'r') as infile:
8290
with open(good_project_path, 'w+') as outfile:
83-
outfile.write(infile.read().replace('./lines-BAD_SOURCE.shp', './lines.shp'))
91+
outfile.write(infile.read().replace('./lines-BAD_SOURCE.shp', './lines.shp').replace('band1_byte_ct_epsg4326_copy-BAD_SOURCE.tif', 'band1_byte_ct_epsg4326_copy.tif'))
8492

8593
# Load the good project
8694
self.assertTrue(p.read(good_project_path))
8795
# Check layer is valid
8896
vector = list(p.mapLayersByName('lines'))[0]
8997
raster = list(p.mapLayersByName('raster'))[0]
98+
raster_copy = list(p.mapLayersByName('raster_copy'))[0]
9099
self.assertTrue(vector.isValid())
91100
self.assertTrue(raster.isValid())
101+
self.assertTrue(raster_copy.isValid())
92102

93103

94104
if __name__ == '__main__':

0 commit comments

Comments
 (0)
Please sign in to comment.