@@ -45,12 +45,15 @@ def test_project_roundtrip(self):
45
45
for ext in ('shp' , 'dbf' , 'shx' , 'prj' ):
46
46
copyfile (os .path .join (TEST_DATA_DIR , 'lines.%s' % ext ), os .path .join (temp_dir .path (), 'lines.%s' % ext ))
47
47
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' ))
48
49
l = QgsVectorLayer (os .path .join (temp_dir .path (), 'lines.shp' ), 'lines' , 'ogr' )
49
50
self .assertTrue (l .isValid ())
50
51
51
52
rl = QgsRasterLayer (os .path .join (temp_dir .path (), 'band1_byte_ct_epsg4326.tif' ), 'raster' , 'gdal' )
52
53
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 ]))
54
57
55
58
# Save project
56
59
project_path = os .path .join (temp_dir .path (), 'project.qgs' )
@@ -60,14 +63,19 @@ def test_project_roundtrip(self):
60
63
bad_project_path = os .path .join (temp_dir .path (), 'project_bad.qgs' )
61
64
with open (project_path , 'r' ) as infile :
62
65
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' ) )
64
67
65
68
# Load the bad project
66
69
self .assertTrue (p .read (bad_project_path ))
67
70
# Check layer is invalid
68
71
vector = list (p .mapLayersByName ('lines' ))[0 ]
69
72
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 ())
70
77
self .assertFalse (vector .isValid ())
78
+ self .assertFalse (raster_copy .isValid ())
71
79
# Try a getFeatures
72
80
self .assertEqual ([f for f in vector .getFeatures ()], [])
73
81
self .assertTrue (raster .isValid ())
@@ -80,15 +88,17 @@ def test_project_roundtrip(self):
80
88
good_project_path = os .path .join (temp_dir .path (), 'project_good.qgs' )
81
89
with open (bad_project_path2 , 'r' ) as infile :
82
90
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' ) )
84
92
85
93
# Load the good project
86
94
self .assertTrue (p .read (good_project_path ))
87
95
# Check layer is valid
88
96
vector = list (p .mapLayersByName ('lines' ))[0 ]
89
97
raster = list (p .mapLayersByName ('raster' ))[0 ]
98
+ raster_copy = list (p .mapLayersByName ('raster_copy' ))[0 ]
90
99
self .assertTrue (vector .isValid ())
91
100
self .assertTrue (raster .isValid ())
101
+ self .assertTrue (raster_copy .isValid ())
92
102
93
103
94
104
if __name__ == '__main__' :
0 commit comments