Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 13, 2024
1 parent 8eee8de commit fce87ff
Showing 1 changed file with 64 additions and 3 deletions.
67 changes: 64 additions & 3 deletions felt/test/test_layer_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
QgsRasterLayer,
QgsCoordinateTransformContext,
QgsCoordinateReferenceSystem,
QgsWkbTypes
QgsWkbTypes,
QgsPalettedRasterRenderer,
QgsRasterContourRenderer
)

from .utilities import get_qgis_app
Expand Down Expand Up @@ -220,13 +222,15 @@ def test_raster_conversion_raw(self):
file = str(TEST_DATA_PATH / 'dem.tif')
layer = QgsRasterLayer(file, 'test')
self.assertTrue(layer.isValid())
# set a renderer we can convert
renderer = QgsPalettedRasterRenderer(layer.dataProvider(), 1, [])
layer.setRenderer(renderer)

exporter = LayerExporter(
QgsCoordinateTransformContext()
)
result = exporter.export_layer_for_felt(
layer,
force_upload_raster_as_styled=False
layer
)
self.assertEqual(result.result, LayerExportResult.Success)
self.assertTrue(result.filename)
Expand Down Expand Up @@ -313,6 +317,63 @@ def test_raster_conversion_styled(self):
self.assertAlmostEqual(out_layer.extent().yMaximum(),
45.8117014376, 3)

def test_raster_conversion_no_fsl_conversion(self):
"""
Test raster layer conversion
"""
file = str(TEST_DATA_PATH / 'dem.tif')
layer = QgsRasterLayer(file, 'test')
self.assertTrue(layer.isValid())

# set a renderer we can't convert to FSL
renderer = QgsRasterContourRenderer(layer.dataProvider())
layer.setRenderer(renderer)

exporter = LayerExporter(
QgsCoordinateTransformContext()
)
result = exporter.export_layer_for_felt(
layer,
force_upload_raster_as_styled=False
)
self.assertEqual(result.result, LayerExportResult.Success)
self.assertTrue(result.filename)
self.assertEqual(result.filename[-4:], '.zip')
with zipfile.ZipFile(result.filename) as z:
tif_files = [f for f in z.namelist() if f.endswith('tif')]
self.assertEqual(len(tif_files), 1)

self.assertEqual(
result.qgis_style_xml[:58],
"<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>"
)

out_layer = QgsRasterLayer(
'/vsizip/{}/{}'.format(result.filename, tif_files[0]),
'test')
self.assertTrue(out_layer.isValid())
self.assertEqual(out_layer.width(), 373)
self.assertEqual(out_layer.height(), 350)
self.assertEqual(out_layer.bandCount(), 4)
self.assertEqual(out_layer.dataProvider().dataType(1),
Qgis.DataType.Byte)
self.assertEqual(out_layer.dataProvider().dataType(2),
Qgis.DataType.Byte)
self.assertEqual(out_layer.dataProvider().dataType(3),
Qgis.DataType.Byte)
self.assertEqual(out_layer.dataProvider().dataType(4),
Qgis.DataType.Byte)
self.assertEqual(out_layer.crs(),
QgsCoordinateReferenceSystem('EPSG:4326'))
self.assertAlmostEqual(out_layer.extent().xMinimum(),
18.6662979442, 3)
self.assertAlmostEqual(out_layer.extent().xMaximum(),
18.7035979442, 3)
self.assertAlmostEqual(out_layer.extent().yMinimum(),
45.7767014376, 3)
self.assertAlmostEqual(out_layer.extent().yMaximum(),
45.8117014376, 3)


if __name__ == "__main__":
suite = unittest.makeSuite(LayerExporterTest)
Expand Down

0 comments on commit fce87ff

Please sign in to comment.