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

Fix duplicate prefix for produce_or_load(; filename) #400

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/saving_files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ function append_prefix_suffix(name, prefix, suffix)
return prefix*'.'*suffix
end
end
if prefix != ""
if prefix != "" && !startswith(name, prefix)
name = prefix*'_'*name
end
if suffix != ""
if suffix != "" && !endswith(name, suffix)
name *= '.'*suffix
end
return name
Expand Down
16 changes: 10 additions & 6 deletions test/savefiles_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,18 @@ end
x
y
end

simulation = Dummy(1,2)
DrWatson.default_prefix(d::Dummy) = "Prefix_"
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) = ""
_, file = produce_or_load(f, simulation, path)
@test basename(file) == "Prefix_x=1_y=2.jld2"

filename = x -> savename(x; connector = " ")
_, file = produce_or_load(f, simulation, path; filename)
@test basename(file) == "Prefix x=1 y=2.jld2"

rm(path; recursive = true, force = true)
end


Expand Down