Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Tests] Check that GDAL Assign Projection updates QgsRasterLayer info
  • Loading branch information
rldhont committed Jul 31, 2020
1 parent 6c44073 commit f5b819f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion python/plugins/processing/tests/GdalAlgorithmsRasterTest.py
Expand Up @@ -28,7 +28,9 @@

from qgis.core import (QgsProcessingContext,
QgsProcessingFeedback,
QgsRectangle)
QgsRectangle,
QgsRasterLayer,
QgsProject)

from qgis.testing import (start_app,
unittest)
Expand Down Expand Up @@ -133,6 +135,40 @@ def testAssignProjection(self):
'-a_srs EPSG:3111 ' +
source])

@unittest.skipIf(os.environ.get('TRAVIS', '') == 'true',
'gdal_edit.py: not found')
def testRunAssignProjection(self):
# Check that assign projection updates QgsRasterLayer info
# GDAL Assign Projection is based on gdal_edit.py

context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
source = os.path.join(testDataPath, 'dem.tif')
alg = AssignProjection()
alg.initAlgorithm()

with tempfile.TemporaryDirectory() as outdir:
fake_dem = os.path.join(outdir, 'dem-fake-crs.tif')

shutil.copy(source, fake_dem)
self.assertTrue(os.path.exists(fake_dem))

rlayer = QgsRasterLayer(fake_dem, "Fake dem")
self.assertTrue(rlayer.isValid())

self.assertEqual(rlayer.crs().authid(), 'EPSG:4326')

project = QgsProject()
project.setFileName(os.path.join(outdir, 'dem-fake-crs.qgs'))
project.addMapLayer(rlayer)
self.assertEqual(project.count(), 1)

context.setProject(project)

alg.run({'INPUT': fake_dem, 'CRS': 'EPSG:3111'},
context, feedback)
self.assertEqual(rlayer.crs().authid(), 'EPSG:3111')

def testGdalTranslate(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
Expand Down

0 comments on commit f5b819f

Please sign in to comment.