Skip to content

Commit

Permalink
Re-enable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed May 3, 2024
1 parent 43a2378 commit 5465ab3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
12 changes: 7 additions & 5 deletions core/test/utils_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,25 +286,27 @@ end
end

@testitem "constraints_from_nodes" begin
using Ribasim: Model, snake_case, nodetypes, is_flow_constraining

toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml")
@test ispath(toml_path)
model = Ribasim.Model(toml_path)
model = Model(toml_path)
(; p) = model.integrator
constraining_types = (:Pump, :Outlet, :LinearResistance)

for type in Ribasim.nodetypes
for type in nodetypes
type == :Terminal && continue # has no parameter field
node = getfield(p, snake_case(type))
if type in constraining_types
@test Ribasim.is_flow_constraining(node)
@test is_flow_constraining(node)
else
@test !Ribasim.is_flow_constraining(node)
@test !is_flow_constraining(node)
end
end
end

@testitem "Node types" begin
using Ribasim: nodetypes, NodeType, Parameters, AbstractParameterNode
using Ribasim: nodetypes, NodeType, Parameters, AbstractParameterNode, snake_case

@test Set(nodetypes) == Set([
:Terminal,
Expand Down
26 changes: 5 additions & 21 deletions core/test/validation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ end
"A Q(h) relationship for TabulatedRatingCurve #2 from the time table has repeated levels, this can not be interpolated."
end

@testitem "Neighbor count validation" skip = true begin
@testitem "Neighbor count validation" begin
using Graphs: DiGraph
using Logging
using MetaGraphsNext: MetaGraph
Expand Down Expand Up @@ -91,19 +91,9 @@ end
set_edge_metadata!(NodeID(:Pump, 6), NodeID(:Basin, 2), EdgeType.flow)
set_edge_metadata!(NodeID(:FractionalFlow, 5), NodeID(:Pump, 6), EdgeType.control)

pump = Ribasim.Pump(
NodeID.(:Pump, [1, 6]),
[true, true],
[0.0, 0.0],
[0.0, 0.0],
[1.0, 1.0],
Dict{Tuple{NodeID, String}, NamedTuple}(),
falses(2),
)

logger = TestLogger()
with_logger(logger) do
@test !Ribasim.valid_n_neighbors(pump, graph)
@test !Ribasim.valid_n_neighbors(:Pump, graph)
end

@test length(logger.logs) == 3
Expand All @@ -120,15 +110,9 @@ end
set_edge_metadata!(NodeID(:FractionalFlow, 5), NodeID(:Basin, 3), EdgeType.flow)
set_edge_metadata!(NodeID(:FractionalFlow, 5), NodeID(:Basin, 4), EdgeType.flow)

fractional_flow = Ribasim.FractionalFlow(
[NodeID(:FractionalFlow, 5)],
[1.0],
Dict{Tuple{NodeID, String}, NamedTuple}(),
)

logger = TestLogger(; min_level = Debug)
with_logger(logger) do
@test !Ribasim.valid_n_neighbors(fractional_flow, graph)
@test !Ribasim.valid_n_neighbors(:FractionalFlow, graph)
end

@test length(logger.logs) == 2
Expand Down Expand Up @@ -209,7 +193,7 @@ end
"PID listened Basin #5 is not on either side of controlled Pump #2."
end

@testitem "FractionalFlow validation" skip = true begin
@testitem "FractionalFlow validation" begin
import SQLite
using Logging
using Ribasim: NodeID
Expand All @@ -224,7 +208,7 @@ end
db_path = Ribasim.input_path(config, config.database)
db = SQLite.DB(db_path)
graph = Ribasim.create_graph(db, config, [1, 1])
fractional_flow = Ribasim.FractionalFlow(db, config)
fractional_flow = Ribasim.FractionalFlow(db, config, graph)

logger = TestLogger()
with_logger(logger) do
Expand Down
4 changes: 4 additions & 0 deletions python/ribasim_testmodels/ribasim_testmodels/invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def invalid_fractional_flow_model() -> Model:
model.basin[2],
model.fractional_flow[8],
)
model.edge.add(
model.fractional_flow[8],
model.terminal[5],
)

return model

Expand Down

0 comments on commit 5465ab3

Please sign in to comment.