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

Move test_save_load_roundtrip to init file #2801

Merged
merged 3 commits into from
Sep 18, 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
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")
lgoettgens marked this conversation as resolved.
Show resolved Hide resolved

testlist = [

Expand Down
Loading