Skip to content

Commit

Permalink
Fix last test wrt logging
Browse files Browse the repository at this point in the history
  • Loading branch information
deltamarnix committed Dec 19, 2023
1 parent 947f68e commit fef8b98
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
12 changes: 5 additions & 7 deletions core/src/logging.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
"""
The type of message that is sent to is_current_module.
The information is generated in LoggingExtras.EarlyFilteredLogger.
is_current_module(log::LogMessageType)::Bool
Returns true if the log message is from the current module or a submodule.
See https://github.com/JuliaLogging/LoggingExtras.jl/blob/d35e7c8cfc197853ee336ace17182e6ed36dca24/src/CompositionalLoggers/earlyfiltered.jl#L39
for the information available in log.
"""
const LogMessageType =
@NamedTuple{level::LogLevel, _module::Module, group::Symbol, id::Symbol}

function is_current_module(log::LogMessageType)::Bool
function is_current_module(log)::Bool
(log._module == @__MODULE__) ||
(parentmodule(log._module) == @__MODULE__) ||
log._module == OrdinaryDiffEq# for the progress bar
log._module == OrdinaryDiffEq # for the progress bar
end

function setup_logger(;
Expand Down
3 changes: 1 addition & 2 deletions core/test/logging_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ end
logger = Ribasim.setup_logger(;
verbosity = Logging.Debug,
stream = io,
module_filter_function = log::Ribasim.LogMessageType ->
log._module == @__MODULE__,
module_filter_function = log -> log._module == @__MODULE__,
)

with_logger(logger) do
Expand Down
6 changes: 4 additions & 2 deletions core/test/run_models_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ end

@testitem "basic model" begin
using Logging: Debug, with_logger
using LoggingExtras
using SciMLBase: successful_retcode
import Tables
using Dates

toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml")
@test ispath(toml_path)

logger = TestLogger()
model = with_logger(logger) do
logger = TestLogger(; min_level = Debug)
filtered_logger = LoggingExtras.EarlyFilteredLogger(Ribasim.is_current_module, logger)
model = with_logger(filtered_logger) do
Ribasim.run(Ribasim.Config(toml_path))
end

Expand Down
4 changes: 2 additions & 2 deletions core/test/validation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
level = [[0.0, 0.0, 1.0]]
area = [[0.0, 100.0, 90]]

logger = TestLogger()
logger = TestLogger(; min_level = Debug)
with_logger(logger) do
@test !valid_profiles(node_id, level, area)
end
Expand Down Expand Up @@ -124,7 +124,7 @@ end
fractional_flow =
Ribasim.FractionalFlow([NodeID(5)], [1.0], Dict{Tuple{Int, String}, NamedTuple}())

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

0 comments on commit fef8b98

Please sign in to comment.