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 1 commit
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
5 changes: 2 additions & 3 deletions src/saving_files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ function produce_or_load(f::Function, config, path::String = "";
"""
end
if filename === nothing
filename = config -> savename(config; kwargs...)
filename = config -> savename(prefix, config, suffix; kwargs...)
end
# Prepare absolute file name
if filename isa AbstractString
name = filename
name = append_prefix_suffix(filename, prefix, suffix)
else
name = string(filename(config))
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
12 changes: 12 additions & 0 deletions test/savefiles_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ 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()

DrWatson.default_prefix(ntuple::NamedTuple) = "Prefix_"

sim, path = produce_or_load(f, simulation, "")
@test path == savename(simulation)
Datseris marked this conversation as resolved.
Show resolved Hide resolved

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


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