Skip to content

Commit

Permalink
Fix duplicate prefix for produce_or_load(; filename)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schulze committed Dec 18, 2023
1 parent cad2a38 commit 74fe134
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
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

0 comments on commit 74fe134

Please sign in to comment.