Skip to content

Commit

Permalink
Tests - Add test data
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Jun 20, 2024
1 parent 842402a commit c7ba841
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 18 deletions.
18 changes: 7 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
*.orig
*.rej
# Temp files
*~
*.o
*.swp
*.pyc
*.DS_Store
*.zip
help/
i18n/
scripts/
test/
.idea/

# Tests data
symbology-style.db

# IDE
.idea/
17 changes: 10 additions & 7 deletions dynamic_layers/dynamic_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions dynamic_layers/dynamic_layers_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """
Expand Down
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__copyright__ = 'Copyright 2024, 3Liz'
__license__ = 'GPL version 3'
__email__ = 'info@3liz.org'
19 changes: 19 additions & 0 deletions tests/base_tests.py
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 8 additions & 0 deletions tests/fixtures/folder_1/lines.geojson
Original file line number Diff line number Diff line change
@@ -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 ] ] } }
]
}
8 changes: 8 additions & 0 deletions tests/fixtures/folder_2/lines.geojson
Original file line number Diff line number Diff line change
@@ -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 ] ] } }
]
}
27 changes: 27 additions & 0 deletions tests/test_basic_replacement.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit c7ba841

Please sign in to comment.