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

Fix CLI tests #691

Merged
merged 7 commits into from
Oct 23, 2023
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
13 changes: 6 additions & 7 deletions build/ribasim_cli/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@


@pytest.mark.parametrize(
"model_name,model_constructor",
ribasim_testmodels.constructors.items(),
"model_constructor",
ribasim_testmodels.constructors.values(),
)
def test_ribasim_cli(model_name, model_constructor, tmp_path):
def test_ribasim_cli(model_constructor, tmp_path):
model = model_constructor()
assert isinstance(model, ribasim.Model)
model.write(tmp_path / model_name)
model.write(tmp_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this the model folder name becomes a random tmp_path instead of the model name. That makes it hard to find the right model for manual inspection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmp_path isn't random.
It gets the name according to the test parameters

Copy link
Member

@visr visr Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to recognize the model name from the tmp_path, so does it put the constructor.__name__ in there? If so that would be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does on my machine.
But please, try it out yourself :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I couldn't afford to download new binaries over 4G to test 😓


executable = (
Path(__file__).parents[2]
Expand All @@ -22,10 +22,9 @@ def test_ribasim_cli(model_name, model_constructor, tmp_path):
/ "bin"
/ "ribasim.exe"
)
config_file = str(tmp_path / "ribasim.toml")
result = subprocess.run([executable, config_file])
result = subprocess.run([executable, tmp_path / "ribasim.toml"])

if model_name.startswith("invalid_"):
if model_constructor.__name__.startswith("invalid_"):
assert result.returncode != 0
else:
assert result.returncode == 0
22 changes: 0 additions & 22 deletions core/test/time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,3 @@ using DataFrames: DataFrame
# some difference is expected since the modeled flow is for the period up to t
@test isapprox(flow_added_1, flow_expected, rtol = 0.005)
end

@testset "User demand interpolation" begin
toml_path = normpath(@__DIR__, "../../generated_testmodels/subnetwork/ribasim.toml")
@test ispath(toml_path)

cfg = Ribasim.Config(toml_path)
db_path = Ribasim.input_path(cfg, cfg.database)
db = SQLite.DB(db_path)

p = Ribasim.Parameters(db, cfg)
(; user) = p
(; demand) = user

t_end = Ribasim.seconds_since(cfg.endtime, cfg.starttime)

@test demand[1][2](0.5 * t_end) ≈ 1.0
@test demand[2][1](0.0) ≈ 0.0
@test demand[2][1](t_end) ≈ 0.0
@test demand[2][3](0.0) ≈ 0.0
@test demand[2][3](t_end / 2) ≈ 1.5
@test demand[2][3](t_end) ≈ 3.0
end
6 changes: 4 additions & 2 deletions python/ribasim_testmodels/ribasim_testmodels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import ribasim_testmodels
from ribasim_testmodels.allocation import (
looped_subnetwork_model,
# looped_subnetwork_model,
subnetwork_model,
user_model,
)
Expand Down Expand Up @@ -74,7 +74,9 @@
"outlet_model",
"user_model",
"subnetwork_model",
"looped_subnetwork_model",
# Disable until this issue is resolved:
# https://github.com/Deltares/Ribasim/issues/692
# "looped_subnetwork_model",
]

# provide a mapping from model name to its constructor, so we can iterate over all models
Expand Down
4 changes: 2 additions & 2 deletions python/ribasim_testmodels/ribasim_testmodels/allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def subnetwork_model():
outlet=outlet,
terminal=terminal,
starttime="2020-01-01 00:00:00",
endtime="2021-01-01 00:00:00",
endtime="2020-01-01 00:00:00",
)

return model
Expand Down Expand Up @@ -528,7 +528,7 @@ def looped_subnetwork_model():
tabulated_rating_curve=rating_curve,
terminal=terminal,
starttime="2020-01-01 00:00:00",
endtime="2021-01-01 00:00:00",
endtime="2020-01-01 00:00:00",
)

return model