-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
test_save_load_roundtrip
to init file
- Loading branch information
1 parent
ebee98c
commit f99b09d
Showing
3 changed files
with
47 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters