diff --git a/.docker/compose.yml b/.docker/compose.yml new file mode 100644 index 000000000..8f6f42924 --- /dev/null +++ b/.docker/compose.yml @@ -0,0 +1,12 @@ +version: '2' + +services: + qgis: + image: qgis/qgis:release-3_34 + container_name: qgis + volumes: + - ../ribasim_qgis/:/tests_directory/ribasim_qgis + environment: + - CI=true + - DISPLAY=:99 + tty: true diff --git a/.docker/start.sh b/.docker/start.sh new file mode 100755 index 000000000..6c583b16b --- /dev/null +++ b/.docker/start.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -eux + +docker compose -f compose.yml up -d --force-recreate --remove-orphans +echo "Installation of the plugin Ribasim" +docker exec -t qgis sh -c "qgis_setup.sh ribasim_qgis" +echo "Containers are running" diff --git a/.docker/stop.sh b/.docker/stop.sh new file mode 100755 index 000000000..08afc0ec6 --- /dev/null +++ b/.docker/stop.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eux + +echo 'Stopping/killing containers' +docker compose -f compose.yml kill +docker compose -f compose.yml rm -f diff --git a/.docker/test.sh b/.docker/test.sh new file mode 100755 index 000000000..b1ce0ec3b --- /dev/null +++ b/.docker/test.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -eux + +docker exec -t qgis sh -c "cd /tests_directory && xvfb-run -a qgis_testrunner.sh ribasim_qgis.tests" diff --git a/.github/workflows/qgis.yml b/.github/workflows/qgis.yml index fc9b302de..3275c8db4 100644 --- a/.github/workflows/qgis.yml +++ b/.github/workflows/qgis.yml @@ -8,27 +8,21 @@ on: pull_request: paths-ignore: [".teamcity/**"] merge_group: -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true jobs: - test: - name: QGIS plugin ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: - - ubuntu-latest - - macOS-latest - - windows-latest - steps: - - uses: actions/checkout@v4 - - uses: prefix-dev/setup-pixi@v0.8.1 - with: - pixi-version: "latest" - - name: Run tests - run: pixi run test-ribasim-qgis-cov - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} + test-qgis: + name: "Test" + runs-on: ubuntu-latest + defaults: + run: + working-directory: .docker + steps: + - uses: actions/checkout@v4 + - uses: prefix-dev/setup-pixi@v0.8.1 + with: + pixi-version: "latest" + - name: Run tests + run: pixi run test-ribasim-qgis-docker + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/pixi.toml b/pixi.toml index e16056b63..346715472 100644 --- a/pixi.toml +++ b/pixi.toml @@ -128,6 +128,7 @@ install-ribasim-qgis = "python ribasim_qgis/scripts/install_ribasim_qgis.py" install-imod-qgis = "python ribasim_qgis/scripts/install_qgis_plugin.py iMOD && python ribasim_qgis/scripts/enable_plugin.py imodqgis" install-plugin-reloader-qgis = "python ribasim_qgis/scripts/install_qgis_plugin.py \"Plugin Reloader\" && python ribasim_qgis/scripts/enable_plugin.py plugin_reloader" install-debugvs-qgis = "python ribasim_qgis/scripts/install_qgis_plugin.py debugvs==0.7 && python ribasim_qgis/scripts/enable_plugin.py debug_vs" +test-ribasim-qgis-docker = { cmd = "sh ./start.sh; sh ./test.sh; sh ./stop.sh", cwd = ".docker" } install-qgis-plugins = { depends_on = [ "install-plugin-reloader-qgis", "install-ribasim-qgis", @@ -137,10 +138,10 @@ install-qgis-plugins = { depends_on = [ test-ribasim-qgis-ui = { cmd = "python ribasim_qgis/scripts/run_qgis_ui_tests.py", depends_on = [ "install-ribasim-qgis", ] } -test-ribasim-qgis = { cmd = "pytest --numprocesses=auto ribasim_qgis/tests", depends_on = [ +test-ribasim-qgis = { cmd = "pytest --numprocesses=auto ribasim_qgis/tests/core", depends_on = [ "install-ribasim-qgis", ] } -test-ribasim-qgis-cov = { cmd = "pytest --numprocesses=auto --cov=ribasim_qgis --cov-report=xml --cov-config=ribasim_qgis/.coveragerc ribasim_qgis/tests", depends_on = [ +test-ribasim-qgis-cov = { cmd = "pytest --numprocesses=auto --cov=ribasim_qgis --cov-report=xml --cov-config=ribasim_qgis/.coveragerc ribasim_qgis/tests/core", depends_on = [ "install-ribasim-qgis", ] } mypy-ribasim-qgis = "mypy ribasim_qgis" diff --git a/ribasim_qgis/.coveragerc b/ribasim_qgis/.coveragerc index 011bc9fa5..e14c37159 100644 --- a/ribasim_qgis/.coveragerc +++ b/ribasim_qgis/.coveragerc @@ -1,6 +1,6 @@ [run] +source = . omit = - ribasim_qgis/resources.py - ribasim_qgis/tests/* - ribasim_qgis/tomllib/* - ribasim_qgis/ui_tests/* + */resources.py + */tests/* + */tomllib/* diff --git a/ribasim_qgis/scripts/run_qgis_ui_tests.py b/ribasim_qgis/scripts/run_qgis_ui_tests.py index bee8e1096..04fda7c4d 100644 --- a/ribasim_qgis/scripts/run_qgis_ui_tests.py +++ b/ribasim_qgis/scripts/run_qgis_ui_tests.py @@ -9,7 +9,7 @@ "--nologo", "--code", "ribasim_qgis/scripts/qgis_testrunner.py", - "ribasim_qgis.ui_tests", + "ribasim_qgis.tests", ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, diff --git a/ribasim_qgis/tests/__init__.py b/ribasim_qgis/tests/__init__.py new file mode 100644 index 000000000..7034cc660 --- /dev/null +++ b/ribasim_qgis/tests/__init__.py @@ -0,0 +1,20 @@ +import sys +from pathlib import Path + +import coverage +from qgis.testing import unittest + +testfolder = Path(__file__).parent + + +def run_all(): + test_loader = unittest.defaultTestLoader + test_suite = test_loader.discover(".", pattern="test_*.py") + + cov = coverage.Coverage(config_file=testfolder.parent / ".coveragerc") + cov.start() + unittest.TextTestRunner(verbosity=3, stream=sys.stdout).run(test_suite) + + cov.stop() + cov.save() + cov.xml_report(outfile=testfolder / "coverage.xml") diff --git a/ribasim_qgis/tests/ui/__init__.py b/ribasim_qgis/tests/ui/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ribasim_qgis/ui_tests/test_load_plugin.py b/ribasim_qgis/tests/ui/test_load_plugin.py similarity index 100% rename from ribasim_qgis/ui_tests/test_load_plugin.py rename to ribasim_qgis/tests/ui/test_load_plugin.py diff --git a/ribasim_qgis/ui_tests/__init__.py b/ribasim_qgis/ui_tests/__init__.py deleted file mode 100644 index 81e3b194e..000000000 --- a/ribasim_qgis/ui_tests/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -import sys - -from qgis.testing import unittest - - -def run_all(): - test_loader = unittest.defaultTestLoader - test_suite = test_loader.discover(".", pattern="test_*.py") - unittest.TextTestRunner(verbosity=3, stream=sys.stdout).run(test_suite)