Skip to content

Commit

Permalink
tweak docstrings, error message, and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ablaom committed Jun 20, 2024
1 parent b4f7fb2 commit 813ba0c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/machines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1089,9 +1089,10 @@ function save(file::Union{String,IO}, mach::Machine)
end

const ERR_INVALID_DEFAULT_LOGGER = ArgumentError(
"`default_logger()` is currently `nothing`. "*
"Either specify an explicit path or stream as "*
"target of the save, or use `default_logger(logger)` "*
"You have attempted to save a machine to the default logger "*
"but `default_logger()` is currently `nothing`. "*
"Either specify an explicit logger, path or stream to save to, "*
"or use `default_logger(logger)` "*
"to change the default logger. "
)

Expand Down
2 changes: 1 addition & 1 deletion src/resampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ const DOC_DEFAULT_LOGGER =
!!! note
In MLJ version prior to 0.21 the default logger is always `nothing`.
Prior to MLJ v0.20.7 (and MLJBase 1.5) the default logger was always `nothing`.
"""

Expand Down
17 changes: 17 additions & 0 deletions test/resampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -932,4 +932,21 @@ end
end
end

# DUMMY LOGGER

struct DummyLogger end

MLJBase.save(logger::DummyLogger, mach::Machine) = mach.model

@testset "default logger" begin
@test isnothing(default_logger())
model = ConstantClassifier()
mach = machine(model, make_moons(10)...)
fit!(mach, verbosity=0)
@test_throws MLJBase.ERR_INVALID_DEFAULT_LOGGER MLJBase.save(mach)
default_logger(DummyLogger())
@test default_logger() == DummyLogger()
@test MLJBase.save(mach) == model
end

true

0 comments on commit 813ba0c

Please sign in to comment.