From 933fc1d4641b23283b207629ebb85f3d683408d9 Mon Sep 17 00:00:00 2001 From: merydian Date: Thu, 24 Oct 2024 09:56:38 +0200 Subject: [PATCH 1/2] feat: also test correctness of proc output --- CHANGELOG.md | 1 + tests/test_proc.py | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67a66a58..69b99243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ RELEASING: --> ## Unreleased +- Also test correctness of processing algorithm output ([#283](https://github.com/GIScience/orstools-qgis-plugin/issues/283)) ### Changed - Use QgsSettings instead of config.yml file to avoid deletion of providers on update ([#108](https://github.com/GIScience/orstools-qgis-plugin/issues/108)) diff --git a/tests/test_proc.py b/tests/test_proc.py index df4cd8d7..401a1500 100644 --- a/tests/test_proc.py +++ b/tests/test_proc.py @@ -22,25 +22,27 @@ class TestProc(unittest.TestCase): def setUpClass(cls) -> None: uri = "point?crs=epsg:4326" cls.point_layer_1 = QgsVectorLayer(uri, "Scratch point layer", "memory") - points_of_interest = [QgsPointXY(-118.2394, 34.0739), QgsPointXY(-118.3215, 34.1399)] + points_of_interest = [QgsPointXY(8.6724, 49.3988), QgsPointXY(8.6908, 49.4094)] for point in points_of_interest: feature = QgsFeature() feature.setGeometry(QgsGeometry.fromPointXY(point)) - cls.point_layer_1.dataProvider().addFeatures([feature]) + cls.point_layer_1.dataProvider().addFeature(feature) cls.point_layer_2 = QgsVectorLayer(uri, "Scratch point layer", "memory") - points_of_interest = [QgsPointXY(-118.5, 34.2), QgsPointXY(-118.5, 34.3)] + points_of_interest = [QgsPointXY(8.4660, 49.4875), QgsPointXY(8.4796, 49.4978)] for point in points_of_interest: feature = QgsFeature() feature.setGeometry(QgsGeometry.fromPointXY(point)) - cls.point_layer_2.dataProvider().addFeatures([feature]) + cls.point_layer_2.dataProvider().addFeature(feature) + uri = "linestring?crs=epsg:4326" cls.line_layer = QgsVectorLayer(uri, "Scratch point layer", "memory") - vertices = [(-118.2394, 34.0739), (-118.3215, 34.1341), (-118.4961, 34.5)] + vertices = [(8.6724, 49.3988), (8.7165, 49.4106), (8.6947, 49.4178)] line_geometry = QgsGeometry.fromPolylineXY([QgsPointXY(x, y) for x, y in vertices]) feature = QgsFeature() feature.setGeometry(line_geometry) - cls.line_layer.dataProvider().addFeatures([feature]) + cls.line_layer.dataProvider().addFeature(feature) + print(line_geometry) cls.feedback = QgsProcessingFeedback() cls.context = QgsProcessingContext() @@ -57,8 +59,6 @@ def test_directions_lines(self): "INPUT_PREFERENCE": 0, "INPUT_PROFILE": 0, "INPUT_PROVIDER": 0, - "INPUT_METRIC": 0, - "LOCATION_TYPE": 0, "OUTPUT": "TEMPORARY_OUTPUT", } @@ -68,6 +68,9 @@ def test_directions_lines(self): self.assertEqual(type(processed_layer), QgsVectorLayer) + feat_length = next(processed_layer.getFeatures()).geometry().length() + self.assertTrue(feat_length > 0) + def test_directions_points_layer(self): parameters = { "INPUT_AVOID_BORDERS": None, @@ -90,6 +93,9 @@ def test_directions_points_layer(self): self.assertEqual(type(processed_layer), QgsVectorLayer) + feat_length = next(processed_layer.getFeatures()).geometry().length() + self.assertTrue(feat_length > 0) + def test_directions_points_layers(self): parameters = { "INPUT_AVOID_BORDERS": None, @@ -115,6 +121,9 @@ def test_directions_points_layers(self): self.assertEqual(type(processed_layer), QgsVectorLayer) + feat_length = next(processed_layer.getFeatures()).geometry().length() + self.assertTrue(feat_length > 0) + def test_isochrones_layer(self): parameters = { "INPUT_AVOID_BORDERS": None, @@ -138,6 +147,9 @@ def test_isochrones_layer(self): self.assertEqual(type(processed_layer), QgsVectorLayer) + feat_area = next(processed_layer.getFeatures()).geometry().area() + self.assertTrue(feat_area > 0) + def test_isochrones_point(self): parameters = { "INPUT_AVOID_BORDERS": None, @@ -160,6 +172,12 @@ def test_isochrones_point(self): self.assertEqual(type(processed_layer), QgsVectorLayer) + feats = processed_layer.getFeatures() + feat_areas = [feat.geometry().area() for feat in feats] + self.assertTrue(feat_areas[0] > 0) + # TODO: This is the wrong way around, because polygon order in isochrones is inverted. + self.assertTrue(feat_areas[0] > feat_areas[1]) + def test_matrix(self): parameters = { "INPUT_END_FIELD": None, @@ -176,3 +194,6 @@ def test_matrix(self): processed_layer = QgsProcessingUtils.mapLayerFromString(dest_id["OUTPUT"], self.context) self.assertEqual(type(processed_layer), QgsVectorLayer) + + feat = next(processed_layer.getFeatures()) + self.assertTrue(feat.attributes()[2] > 0) From e99cc063597638117510dfe01432a2f08aebcfe2 Mon Sep 17 00:00:00 2001 From: merydian Date: Thu, 24 Oct 2024 10:01:47 +0200 Subject: [PATCH 2/2] style: run ruff --- tests/conftest.py | 1 + tests/test_gui.py | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 78dcd20f..d2ac0286 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,6 +12,7 @@ s = QgsSettings() data = s.value("ORStools/config") + def pytest_sessionstart(session): """ Called after the Session object has been created and diff --git a/tests/test_gui.py b/tests/test_gui.py index b9b0372b..4986b812 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -63,6 +63,4 @@ def test_ORStoolsDialog(self): dlg.line_tool.canvasDoubleClickEvent(map_dclick) self.assertTrue(dlg.isVisible()) - self.assertEqual( - dlg.routing_fromline_list.item(0).text(), "Point 0: -0.187575, 56.516620" - ) + self.assertEqual(dlg.routing_fromline_list.item(0).text(), "Point 0: -0.187575, 56.516620")