Skip to content

Commit

Permalink
Merge branch 'main' into better_negative_storage_support
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Aug 29, 2024
2 parents d3dcdb1 + b80a79a commit 02e2a79
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 40 deletions.
12 changes: 12 additions & 0 deletions .docker/compose.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions .docker/start.sh
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions .docker/stop.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .docker/test.sh
Original file line number Diff line number Diff line change
@@ -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"
40 changes: 17 additions & 23 deletions .github/workflows/qgis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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/[email protected]
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 }}
5 changes: 3 additions & 2 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion python/ribasim/ribasim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ def read(cls, filepath: str | PathLike[str]) -> "Model":
filepath : str | PathLike[str]
The path to the TOML file.
"""
if not Path(filepath).is_file():
raise FileNotFoundError(f"File '{filepath}' does not exist.")
return cls(filepath=filepath) # type: ignore

def write(self, filepath: str | PathLike[str]) -> Path:
Expand Down Expand Up @@ -290,7 +292,12 @@ def _load(cls, filepath: Path | None) -> dict[str, Any]:

directory = filepath.parent / config.get("input_dir", ".")
context_file_loading.get()["directory"] = directory
context_file_loading.get()["database"] = directory / "database.gpkg"
db_path = directory / "database.gpkg"

if not db_path.is_file():
raise FileNotFoundError(f"Database file '{db_path}' does not exist.")

context_file_loading.get()["database"] = db_path

return config
else:
Expand Down
1 change: 1 addition & 0 deletions python/ribasim/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,6 @@ def test_datetime_timezone():
def test_minimal_toml():
# Check if the TOML used in QGIS tests is still valid.
toml_path = Path(__file__).parents[3] / "ribasim_qgis/tests/data/simple_valid.toml"
(toml_path.parent / "database.gpkg").touch() # database file must exist for `read`
model = ribasim.Model.read(toml_path)
assert model.crs == "EPSG:28992"
17 changes: 17 additions & 0 deletions python/ribasim/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import pandas as pd
import pytest
import tomli_w
import xugrid
from pydantic import ValidationError
from pyproj import CRS
Expand Down Expand Up @@ -228,3 +229,19 @@ def test_styles(tabulated_rating_curve: Model, tmp_path):
model.write(tmp_path / "basic" / "ribasim.toml")
with connect(tmp_path / "basic" / "database.gpkg") as conn:
assert conn.execute("SELECT COUNT(*) FROM layer_styles").fetchone()[0] == 3


def test_non_existent_files(tmp_path):
with pytest.raises(
FileNotFoundError, match="File 'non_existent_file.toml' does not exist."
):
Model.read("non_existent_file.toml")

# Create a TOML file without a database.gpkg
content = {"input_path": str(tmp_path)}
toml_path = tmp_path / "test.toml"
with open(toml_path, "wb") as f:
tomli_w.dump(content, f)

with pytest.raises(FileNotFoundError, match=r"Database file .* does not exist\."):
Model.read(toml_path)
8 changes: 4 additions & 4 deletions ribasim_qgis/.coveragerc
Original file line number Diff line number Diff line change
@@ -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/*
2 changes: 1 addition & 1 deletion ribasim_qgis/scripts/run_qgis_ui_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions ribasim_qgis/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
Empty file.
File renamed without changes.
9 changes: 0 additions & 9 deletions ribasim_qgis/ui_tests/__init__.py

This file was deleted.

0 comments on commit 02e2a79

Please sign in to comment.