Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QGIS: Update minimal TOML with new required fields #1647

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions python/ribasim/tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from pathlib import Path

import numpy as np
import pytest
Expand Down Expand Up @@ -202,3 +203,10 @@ def test_datetime_timezone():
assert isinstance(model.endtime, datetime)
assert model.starttime.tzinfo is None
assert model.endtime.tzinfo is None


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"
model = ribasim.Model.read(toml_path)
assert model.crs == "EPSG:28992"
2 changes: 2 additions & 0 deletions ribasim_qgis/tests/data/simple_valid.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
starttime = 2020-01-01 00:00:00
endtime = 2021-01-01 00:00:00
crs = "EPSG:28992"
input_dir = "."
results_dir = "results"
ribasim_version = "2024.9.0"
8 changes: 5 additions & 3 deletions ribasim_qgis/widgets/dataset_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ def remove_geopackage_layers(self) -> None:

# Start deleting
elements = {item.element for item in selection} # type: ignore[attr-defined] # TODO: dynamic item.element should be in some dict.
qgs_instance = QgsProject.instance()
assert qgs_instance is not None
project = QgsProject.instance()
assert project is not None

for element in elements:
layer = element.layer
# QGIS layers
if layer is None:
continue
try:
qgs_instance.removeMapLayer(layer.id())
project.removeMapLayer(layer.id())
except (RuntimeError, AttributeError) as e:
if e.args[0] in (
"wrapped C/C++ object of type QgsVectorLayer has been deleted",
Expand Down Expand Up @@ -268,8 +268,10 @@ def _write_new_model(self) -> None:
[
f"starttime = {datetime(2020, 1, 1)}\n",
f"endtime = {datetime(2021, 1, 1)}\n",
f'crs = "{self.ribasim_widget.crs.authid()}"\n',
'input_dir = "."\n',
'results_dir = "results"\n',
'ribasim_version = "2024.9.0"\n',
deltamarnix marked this conversation as resolved.
Show resolved Hide resolved
]
)

Expand Down