Skip to content

Commit

Permalink
Move test_save_load_roundtrip to init file
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Sep 14, 2023
1 parent ebee98c commit f99b09d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
43 changes: 0 additions & 43 deletions test/Serialization/basic_types.jl
Original file line number Diff line number Diff line change
@@ -1,46 +1,3 @@
function test_save_load_roundtrip(func, path, original::T; params=nothing) where T
# save and load from a file
filename = joinpath(path, "original.json")
save(filename, original)
loaded = load(filename; params=params)
if T <: Vector
@test loaded isa Vector
else
@test loaded isa T
end
func(loaded)

# save and load from an IO buffer
io = IOBuffer()
save(io, original)
seekstart(io)
loaded = load(io; params=params)

if T <: Vector
@test loaded isa Vector
else
@test loaded isa T
end
func(loaded)

# save and load from an IO buffer, with prescribed type
io = IOBuffer()
save(io, original)
seekstart(io)
loaded = load(io, type=T, params=params)
if T <: Vector
@test loaded isa Vector
else
@test loaded isa T
end
func(loaded)

# test loading on a empty state
save(filename, original)
reset_global_serializer_state()
loaded = load(filename; params=params)
end

@testset "basic_types" begin

mktempdir() do path
Expand Down
46 changes: 46 additions & 0 deletions test/init_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This file is dedicated for code that needs to be run on every worker before
# running the tests. This is useful for test-code that is called from multiple files
# that may run on different workers.

function test_save_load_roundtrip(func, path, original::T; params=nothing) where T
# save and load from a file
filename = joinpath(path, "original.json")
save(filename, original)
loaded = load(filename; params=params)
if T <: Vector
@test loaded isa Vector
else
@test loaded isa T
end
func(loaded)

# save and load from an IO buffer
io = IOBuffer()
save(io, original)
seekstart(io)
loaded = load(io; params=params)

if T <: Vector
@test loaded isa Vector
else
@test loaded isa T
end
func(loaded)

# save and load from an IO buffer, with prescribed type
io = IOBuffer()
save(io, original)
seekstart(io)
loaded = load(io, type=T, params=params)
if T <: Vector
@test loaded isa Vector
else
@test loaded isa T
end
func(loaded)

# test loading on a empty state
save(filename, original)
reset_global_serializer_state()
loaded = load(filename; params=params)
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ end
Base.cumulative_compile_timing(true)
end

println("Making test list")
@everywhere include("init_tests.jl")

testlist = [

Expand Down

0 comments on commit f99b09d

Please sign in to comment.