|
| 1 | + |
1 | 2 | from qgis.PyQt.QtWidgets import QLineEdit
|
2 |
| -from qgis._core import QgsSettings |
| 3 | +from qgis._core import ( |
| 4 | + QgsSettings, |
| 5 | + QgsVectorLayer, |
| 6 | + QgsFeature, |
| 7 | + QgsGeometry, |
| 8 | + QgsProject, |
| 9 | + QgsPointXY, |
| 10 | +) |
3 | 11 | from qgis.gui import QgsCollapsibleGroupBox
|
4 | 12 | from qgis.testing import unittest
|
5 | 13 |
|
|
22 | 30 |
|
23 | 31 | @pytest.mark.filterwarnings("ignore:.*imp module is deprecated.*")
|
24 | 32 | class TestGui(unittest.TestCase):
|
| 33 | + def tearDown(self): |
| 34 | + """Run after each test""" |
| 35 | + # Clean up layers |
| 36 | + QgsProject.instance().removeAllMapLayers() |
| 37 | + |
25 | 38 | def test_without_live_preview(self):
|
26 | 39 | from ORStools.gui.ORStoolsDialog import ORStoolsDialog
|
27 | 40 | from ORStools.gui.ORStoolsDialogConfig import ORStoolsDialogConfigMain
|
@@ -358,3 +371,42 @@ def test_ORStoolsDialogConfig_url(self):
|
358 | 371 | "POINT(8.67251100000000008 49.39887900000000087)",
|
359 | 372 | next(layer.getFeatures()).geometry().asPolyline()[0].asWkt(),
|
360 | 373 | )
|
| 374 | + |
| 375 | + def test_load_valid_point_layer(self): |
| 376 | + """Test loading vertices from valid point layer.""" |
| 377 | + from ORStools.gui.ORStoolsDialog import ORStoolsDialogMain |
| 378 | + |
| 379 | + dialog_main = ORStoolsDialogMain(IFACE) |
| 380 | + dialog_main._init_gui_control() |
| 381 | + |
| 382 | + # Create test layers |
| 383 | + self.point_layer = QgsVectorLayer("Point?crs=EPSG:4326", "test_points", "memory") |
| 384 | + self.line_layer = QgsVectorLayer("LineString?crs=EPSG:4326", "test_lines", "memory") |
| 385 | + |
| 386 | + # Add 3 features to point layer |
| 387 | + for coords in [(1, 2), (3, 4), (5, 6)]: |
| 388 | + feat = QgsFeature() |
| 389 | + feat.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(*coords))) |
| 390 | + self.point_layer.dataProvider().addFeature(feat) |
| 391 | + |
| 392 | + QgsProject.instance().addMapLayers([self.point_layer, self.line_layer]) |
| 393 | + |
| 394 | + # Run test |
| 395 | + dialog_main.dlg.load_vertices_from_layer("ok") |
| 396 | + |
| 397 | + # Verify |
| 398 | + self.assertTrue(dialog_main.dlg.line_tool is not None) |
| 399 | + self.assertEqual(dialog_main.dlg.routing_fromline_list.count(), 3) |
| 400 | + self.assertIsInstance(dialog_main.dlg.rubber_band, QgsRubberBand) |
| 401 | + |
| 402 | + def test_user_cancels_operation(self): |
| 403 | + """Test when user cancels the dialog.""" |
| 404 | + from ORStools.gui.ORStoolsDialog import ORStoolsDialogMain |
| 405 | + |
| 406 | + dialog_main = ORStoolsDialogMain(IFACE) |
| 407 | + dialog_main._init_gui_control() |
| 408 | + dialog_main.dlg.load_vertices_from_layer("not_ok") |
| 409 | + |
| 410 | + self.assertTrue(dialog_main.dlg.line_tool is not None) |
| 411 | + self.assertEqual(dialog_main.dlg.routing_fromline_list.count(), 0) |
| 412 | + self.assertNotIsInstance(dialog_main.dlg.rubber_band, QgsRubberBand) |
0 commit comments