Skip to content

Commit 9600da6

Browse files
committed
Move to qgis_pytest test framework; refactor logging
1 parent dac2a75 commit 9600da6

31 files changed

Lines changed: 990 additions & 726 deletions

Makefile

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ SHELL:=bash
22

33
PYTHON_MODULE=lizmap
44

5-
QGIS_VERSION ?= 3.40
65

76
-include .localconfig.mk
87

@@ -17,7 +16,7 @@ ifdef VIRTUAL_ENV
1716
# Always prefer active environment
1817
ACTIVE_VENV=--active
1918
endif
20-
UV_RUN=uv run $(ACTIVE_VENV)
19+
UV=uv run $(ACTIVE_VENV)
2120
endif
2221

2322

@@ -32,13 +31,6 @@ REQUIREMENTS_GROUPS= \
3231

3332
REQUIREMENTS=$(patsubst %, requirements/%.txt, $(REQUIREMENTS_GROUPS))
3433

35-
# Update only packaging dependencies
36-
# Waiting for https://github.com/astral-sh/uv/issues/13705
37-
update-packaging-dependencies::
38-
uv lock -P qgis-plugin-package-ci -P qgis-plugin-transifex-ci
39-
40-
update-packaging-dependencies:: update-requirements
41-
4234
update-requirements: $(REQUIREMENTS)
4335

4436
# Require uv (https://docs.astral.sh/uv/) for extracting
@@ -56,53 +48,92 @@ requirements/%.txt: uv.lock
5648
# Static analysis
5749
#
5850

59-
LINT_TARGETS=$(PYTHON_MODULE) tests $(EXTRA_LINT_TARGETS)
51+
LINT_TARGETS=$(PYTHON_MODULE) $(EXTRA_LINT_TARGETS)
6052

6153
lint:
62-
@ $(UV_RUN) ruff check --output-format=concise $(LINT_TARGETS)
54+
@ $(UV) ruff check --output-format=concise $(LINT_TARGETS)
55+
@ $(UV) ruff check --output-format=concise --target-version=py310 tests
6356

6457
lint-fix:
65-
@ $(UV_RUN) ruff check --fix $(LINT_TARGETS)
58+
@ $(UV) ruff check --fix $(LINT_TARGETS)
59+
@ $(UV) ruff check --fix --target-version=py310 tests
60+
61+
lint-preview:
62+
@ $(UV) ruff check --preview --output-format=concise $(LINT_TARGETS)
6663

6764
format:
68-
@ $(UV_RUN) ruff format $(LINT_TARGETS)
65+
@ $(UV) ruff format $(LINT_TARGETS)
6966

7067
typecheck:
71-
$(UV_RUN) mypy $(PYTHON_MODULE)
68+
$(UV) mypy $(PYTHON_MODULE)
69+
$(UV) mypy tests --python-version 3.10
7270

7371
scan:
74-
@ $(UV_RUN) bandit -r $(PYTHON_MODULE) $(SCAN_OPTS)
72+
@ $(UV) bandit -r $(PYTHON_MODULE) $(SCAN_OPTS)
7573

7674

77-
check-uv-install:
78-
@which uv > /dev/null || { \
79-
echo "You must install uv (https://docs.astral.sh/uv/)"; \
80-
exit 1; \
81-
}
82-
8375
#
8476
# Tests
8577
#
8678

8779
test:
88-
$(UV_RUN) pytest -v tests/
80+
$(UV) pytest -v tests/
8981

9082
#
9183
# Test using docker image
9284
#
93-
QGIS_IMAGE_REPOSITORY ?= qgis/qgis
85+
86+
ifdef REGISTRY_URL
87+
REGISTRY_PREFIX=$(REGISTRY_URL)/
88+
else
89+
REGISTRY_PREFIX=3liz
90+
endif
91+
92+
QGIS_VERSION ?= 3.44
93+
QGIS_IMAGE_REPOSITORY ?= ${REGISTRY_PREFIX}qgis-platform
9494
QGIS_IMAGE_TAG ?= $(QGIS_IMAGE_REPOSITORY):$(QGIS_VERSION)
9595

9696
export QGIS_VERSION
9797
export QGIS_IMAGE_TAG
9898
export UID=$(shell id -u)
9999
export GID=$(shell id -g)
100+
100101
docker-test:
101-
cd .docker && docker compose up \
102+
set -e; \
103+
cd .docker;
104+
docker compose up \
102105
--quiet-pull \
103106
--abort-on-container-exit \
104-
--exit-code-from qgis
105-
cd .docker && docker compose down -v
107+
--exit-code-from qgis; \
108+
docker compose down -v;
109+
110+
#
111+
# Install/sync
112+
#
113+
114+
sync:
115+
@echo "Synchronizing python's environment with frozen dependencies"
116+
uv sync --all-groups --frozen --all-extras
117+
118+
install-dev::
119+
@echo "Creating virtual python environment"
120+
uv venv --system-site-packages --no-managed-python
121+
122+
install-dev:: sync
123+
124+
#
125+
# Coverage
126+
#
127+
128+
# Run tests coverage
129+
covtests:
130+
@echo "Running coverage tests"
131+
@ $(UV) coverage run -m pytest tests/
132+
133+
coverage: covtests
134+
@echo "Building coverage html"
135+
@ $(UV) coverage html
136+
106137

107138
#
108139
# Code managment

lizmap/dialogs/dock_html_preview.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
"""
12
__copyright__ = 'Copyright 2023, 3Liz'
23
__license__ = 'GPL version 3'
34
__email__ = 'info@3liz.org'
4-
5-
import logging
6-
5+
"""
76
from qgis.core import (
87
QgsApplication,
98
QgsExpression,
@@ -26,10 +25,8 @@
2625
)
2726
from qgis.utils import iface
2827

29-
from lizmap.toolbelt.i18n import tr
30-
from lizmap.toolbelt.resources import resources_path
31-
32-
LOGGER = logging.getLogger('Lizmap')
28+
from ..toolbelt.i18n import tr
29+
from ..toolbelt.resources import resources_path
3330

3431
# Detect available Web widget
3532
WEBKIT_AVAILABLE = False

lizmap/dialogs/html_editor.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1+
"""
12
__copyright__ = 'Copyright 2023, 3Liz'
23
__license__ = 'GPL version 3'
34
__email__ = 'info@3liz.org'
4-
5-
import logging
6-
5+
"""
76
from qgis.core import QgsVectorLayer
87
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout
98

10-
from lizmap.toolbelt.i18n import tr
11-
from lizmap.widgets.html_editor import HtmlEditorWidget
12-
13-
LOGGER = logging.getLogger('Lizmap')
9+
from ..toolbelt.i18n import tr
10+
from ..widgets.html_editor import HtmlEditorWidget
1411

1512

1613
class HtmlEditorDialog(QDialog):

lizmap/dialogs/main.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
from __future__ import annotations
2-
3-
import logging
4-
51
from pathlib import Path
62
from typing import TYPE_CHECKING, Any
73

@@ -64,15 +60,17 @@
6460
simplify_provider_side,
6561
use_estimated_metadata,
6662
)
67-
from lizmap.qt_style_sheets import COMPLETE_STYLE_SHEET
68-
from lizmap.saas import fix_ssl, is_lizmap_cloud
69-
from lizmap.table_manager.upload_files import TableFilesManager
70-
from lizmap.toolbelt.i18n import tr
71-
from lizmap.toolbelt.layer import relative_path
72-
from lizmap.toolbelt.resources import load_ui, resources_path
73-
from lizmap.toolbelt.strings import human_size
74-
from lizmap.toolbelt.version import qgis_version_info
75-
from lizmap.widgets.check_project import Checks, Headers, TableCheck
63+
64+
from .. import logger
65+
from ..qt_style_sheets import COMPLETE_STYLE_SHEET
66+
from ..saas import fix_ssl, is_lizmap_cloud
67+
from ..table_manager.upload_files import TableFilesManager
68+
from ..toolbelt.i18n import tr
69+
from ..toolbelt.layer import relative_path
70+
from ..toolbelt.resources import load_ui, resources_path
71+
from ..toolbelt.strings import human_size
72+
from ..toolbelt.version import qgis_version_info
73+
from ..widgets.check_project import Checks, Headers, TableCheck
7674

7775
WEBKIT_AVAILABLE = False
7876
try:
@@ -99,7 +97,6 @@
9997

10098

10199
FORM_CLASS = load_ui('ui_lizmap.ui')
102-
LOGGER = logging.getLogger("Lizmap")
103100

104101

105102
class LizmapDialog(QDialog, FORM_CLASS):
@@ -734,7 +731,7 @@ def check_qgis_version(self, message_bar: bool = False, widget: bool = False) ->
734731
return False
735732

736733
title = tr('QGIS server version is lower than QGIS desktop version')
737-
LOGGER.error(title)
734+
logger.error(title)
738735

739736
description = tr('Your QGIS desktop is writing QGS project in the future compare to QGIS server.')
740737

@@ -1373,7 +1370,7 @@ def select_unknown_features_group(self):
13731370
")"
13741371
)
13751372
layer.removeSelection()
1376-
LOGGER.debug("Expression used for checking groups not on the server :\n" + expression)
1373+
logger.debug("Expression used for checking groups not on the server :\n" + expression)
13771374
layer.selectByExpression(expression)
13781375
count = layer.selectedFeatureCount()
13791376
self.display_message_bar(
@@ -1429,5 +1426,5 @@ def activateWindow(self):
14291426
""" When the dialog displayed, to trigger functions in the plugin when the dialog is opening. """
14301427
self.check_project_thumbnail()
14311428
self.check_action_file_exists()
1432-
LOGGER.info("Opening the Lizmap dialog.")
1429+
logger.info("Opening the Lizmap dialog.")
14331430
super().activateWindow()

lizmap/dialogs/news.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1+
"""
12
__copyright__ = 'Copyright 2024, 3Liz'
23
__license__ = 'GPL version 3'
34
__email__ = 'info@3liz.org'
4-
5-
import logging
6-
5+
"""
76
from qgis.core import QgsSettings
87
from qgis.PyQt.QtCore import Qt, QUrl
98
from qgis.PyQt.QtGui import QDesktopServices, QPixmap
109
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox
1110

12-
from lizmap.definitions.definitions import LwcVersions
13-
from lizmap.definitions.online_help import online_lwc_help
14-
from lizmap.definitions.qgis_settings import Settings
15-
from lizmap.toolbelt.i18n import tr
16-
from lizmap.toolbelt.resources import load_ui, resources_path
11+
from ..definitions.definitions import LwcVersions
12+
from ..definitions.online_help import online_lwc_help
13+
from ..definitions.qgis_settings import Settings
14+
from ..toolbelt.i18n import tr
15+
from ..toolbelt.resources import load_ui, resources_path
1716

18-
LOGGER = logging.getLogger('Lizmap')
1917
FORM_CLASS = load_ui('ui_news.ui')
2018

2119

0 commit comments

Comments
 (0)