From c7ba84122b725bfac899675e924e0df3ad0684ae Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Thu, 20 Jun 2024 17:20:42 +0200 Subject: [PATCH] Tests - Add test data --- .gitignore | 18 +++++++---------- dynamic_layers/dynamic_layers.py | 17 +++++++++------- dynamic_layers/dynamic_layers_dialog.py | 1 + tests/__init__.py | 3 +++ tests/base_tests.py | 19 +++++++++++++++++ tests/fixtures/folder_1/lines.geojson | 8 ++++++++ tests/fixtures/folder_2/lines.geojson | 8 ++++++++ tests/test_basic_replacement.py | 27 +++++++++++++++++++++++++ 8 files changed, 83 insertions(+), 18 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/base_tests.py create mode 100755 tests/fixtures/folder_1/lines.geojson create mode 100755 tests/fixtures/folder_2/lines.geojson create mode 100644 tests/test_basic_replacement.py diff --git a/.gitignore b/.gitignore index 437f721..f16024c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,9 @@ -*.orig -*.rej +# Temp files *~ -*.o -*.swp *.pyc -*.DS_Store -*.zip -help/ -i18n/ -scripts/ -test/ -.idea/ \ No newline at end of file + +# Tests data +symbology-style.db + +# IDE +.idea/ diff --git a/dynamic_layers/dynamic_layers.py b/dynamic_layers/dynamic_layers.py index bbfe2ba..5b0e129 100644 --- a/dynamic_layers/dynamic_layers.py +++ b/dynamic_layers/dynamic_layers.py @@ -35,6 +35,8 @@ from dynamic_layers.dynamic_layers_engine import DynamicLayersEngine from dynamic_layers.tools import resources_path +GREEN = QColor(175, 208, 126) + class DynamicLayers: """QGIS Plugin Implementation.""" @@ -352,7 +354,7 @@ def populate_layer_table(self): i = 0 if layer.customProperty('dynamicDatasourceActive') == str(True): - bg = QColor(175, 208, 126) + bg = GREEN else: bg = Qt.transparent @@ -421,12 +423,12 @@ def on_row_selection_changed(self): # Get selected lines lines = self.dlg.twLayers.selectionModel().selectedRows() - if not lines: + if len(lines) < 1: return layer = None self.selectedLayer = None - is_active = False + # is_active = False if show_layer_properties: row = lines[0].row() @@ -484,8 +486,9 @@ def on_cb_datasource_active_change(self): # Get selected lines lines = self.dlg.twLayers.selectionModel().selectedRows() - if lines != 1: + if len(lines) != 1: return + for index in lines: row = index.row() @@ -494,7 +497,7 @@ def on_cb_datasource_active_change(self): # Change layer line background color in the table if self.dlg.cbDatasourceActive.isChecked(): - bg = QColor(175, 208, 126) + bg = GREEN else: bg = Qt.transparent for i in range(0, 3): @@ -683,7 +686,7 @@ def on_remove_variable_clicked(self): # Get selected lines lines = self.dlg.twVariableList.selectionModel().selectedRows() - if not lines or len(lines) != 1: + if len(lines) != 1: return row = lines[0].row() @@ -758,7 +761,7 @@ def on_copy_from_project_clicked(self): if previous_title != '' and previous_title != p_title: ask = True - previous_abstract = self.dlg.inProjectAbstract.text() + previous_abstract = self.dlg.inProjectAbstract.toPlainText() if previous_abstract != '' and previous_abstract != p_abstract: ask = True diff --git a/dynamic_layers/dynamic_layers_dialog.py b/dynamic_layers/dynamic_layers_dialog.py index 11dc2af..73c80dc 100644 --- a/dynamic_layers/dynamic_layers_dialog.py +++ b/dynamic_layers/dynamic_layers_dialog.py @@ -64,6 +64,7 @@ def __init__(self, parent: QDialog = None): self.bt_open_expression.clicked.connect(self.open_expression_builder) self.inProjectShortName.setVisible(False) + self.label_5.setVisible(False) def open_expression_builder(self): """ Open the expression builder helper. """ diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..110db3c --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,3 @@ +__copyright__ = 'Copyright 2024, 3Liz' +__license__ = 'GPL version 3' +__email__ = 'info@3liz.org' diff --git a/tests/base_tests.py b/tests/base_tests.py new file mode 100644 index 0000000..742db31 --- /dev/null +++ b/tests/base_tests.py @@ -0,0 +1,19 @@ +__copyright__ = 'Copyright 2024, 3Liz' +__license__ = 'GPL version 3' +__email__ = 'info@3liz.org' + +import unittest + +from qgis.core import QgsApplication + + +class BaseTests(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls.qgs = QgsApplication([], False) + cls.qgs.initQgis() + + @classmethod + def tearDownClass(cls): + cls.qgs.exitQgis() diff --git a/tests/fixtures/folder_1/lines.geojson b/tests/fixtures/folder_1/lines.geojson new file mode 100755 index 0000000..f40fd51 --- /dev/null +++ b/tests/fixtures/folder_1/lines.geojson @@ -0,0 +1,8 @@ +{ +"type": "FeatureCollection", +"name": "lines", +"features": [ +{ "type": "Feature", "properties": { "id": 1, "name": "1 Name" }, "geometry": { "type": "LineString", "coordinates": [ [ 3.8540, 43.6220 ], [ 3.8970, 43.6220 ] ] } }, +{ "type": "Feature", "properties": { "id": 2, "name": "2 Name" }, "geometry": { "type": "LineString", "coordinates": [ [ 3.8540, 43.5786 ], [ 3.8970, 43.5786 ] ] } } +] +} diff --git a/tests/fixtures/folder_2/lines.geojson b/tests/fixtures/folder_2/lines.geojson new file mode 100755 index 0000000..944f5d4 --- /dev/null +++ b/tests/fixtures/folder_2/lines.geojson @@ -0,0 +1,8 @@ +{ +"type": "FeatureCollection", +"name": "lines", +"features": [ +{ "type": "Feature", "properties": { "id": 1, "name": "1 Name" }, "geometry": { "type": "LineString", "coordinates": [ [ 3.8540, 43.6220 ], [ 3.8540, 43.5786 ] ] } }, +{ "type": "Feature", "properties": { "id": 2, "name": "2 Name" }, "geometry": { "type": "LineString", "coordinates": [ [ 3.8970, 43.6220 ], [ 3.8970, 43.5786 ] ] } } +] +} diff --git a/tests/test_basic_replacement.py b/tests/test_basic_replacement.py new file mode 100644 index 0000000..2534909 --- /dev/null +++ b/tests/test_basic_replacement.py @@ -0,0 +1,27 @@ +__copyright__ = 'Copyright 2024, 3Liz' +__license__ = 'GPL version 3' +__email__ = 'info@3liz.org' + +import unittest + +from pathlib import Path + +from qgis.core import QgsVectorLayer +from qgis.core import QgsProject + +from tests.base_tests import BaseTests + + +class TestBasicReplacement(BaseTests): + + def test_replacement_map_layer(self): + """ Test datasource can be replaced. """ + project = QgsProject() + + vector = QgsVectorLayer(str(Path("fixtures/folder_1/lines.geojson")), "Layer 1") + project.addMapLayer(vector) + self.assertEqual(1, len(project.mapLayers())) + + +if __name__ == '__main__': + unittest.main()