test_qgsrasterfilewritertask.py: test failure

This commit is contained in:
Even Rouault 2019-09-15 23:48:32 +02:00 committed by Nyall Dawson
parent 5e70084d32
commit bbaa62af0c

View File

@ -99,6 +99,30 @@ class TestQgsRasterFileWriterTask(unittest.TestCase):
self.assertFalse(self.fail)
self.assertTrue(os.path.exists(tmp))
def testFail(self):
"""test error writing a layer"""
path = os.path.join(unitTestDataPath(), 'raster', 'with_color_table.tif')
raster_layer = QgsRasterLayer(path, "test")
self.assertTrue(raster_layer.isValid())
pipe = QgsRasterPipe()
self.assertTrue(pipe.set(raster_layer.dataProvider().clone()))
tmp = create_temp_filename("/this/is/invalid/file.tif")
writer = QgsRasterFileWriter(tmp)
task = QgsRasterFileWriterTask(writer, pipe, 100, 100, raster_layer.extent(), raster_layer.crs(), QgsCoordinateTransformContext())
task.writeComplete.connect(self.onSuccess)
task.errorOccurred.connect(self.onFail)
QgsApplication.taskManager().addTask(task)
while not self.success and not self.fail:
QCoreApplication.processEvents()
self.assertFalse(self.success)
self.assertTrue(self.fail)
if __name__ == '__main__':
unittest.main()