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

Removing double prefixes bug in produce_or_load #393

Merged
merged 5 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 7 additions & 7 deletions src/saving_files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ function produce_or_load(f::Function, config, path::String = "";
for the keyword `filename` as `filename = config -> savename(config; kwargs...)`
"""
end
if filename === nothing
filename = config -> savename(config; kwargs...)
end
# Prepare absolute file name
if filename isa AbstractString
name = filename
else
if filename === nothing
filename = config -> savename(prefix, config, suffix; kwargs...)
name = filename(config)
elseif filename isa AbstractString
name = append_prefix_suffix(filename, prefix, suffix)
else #if filename isa Function
name = string(filename(config))
name = append_prefix_suffix(name, prefix, suffix)
end
name = append_prefix_suffix(name, prefix, suffix)
file = joinpath(path, name)
# Run the remaining logic on whether to produce or load
if !force && isfile(file)
Expand Down
17 changes: 17 additions & 0 deletions test/savefiles_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,23 @@ end
rm(path; recursive = true, force = true)
end

# Testing proper filenames when default_prefix was modified. See https://github.com/JuliaDynamics/DrWatson.jl/issues/392
@testset "@produce_or_load with default_prefix modified" begin
path = mktempdir()

struct Dummy
x
y
end
simulation = Dummy(1,2)
DrWatson.default_prefix(d::Dummy) = "Prefix_"

sim, path = produce_or_load(f, simulation, "")
@test path == savename(simulation, "jld2")

rm(path)
DrWatson.default_prefix(ntuple::NamedTuple) = ""
end


################################################################################
Expand Down