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 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
6 changes: 5 additions & 1 deletion experimental/FTheoryTools/test/tate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ t = global_tate_model(base; completeness_check = false)
@test is_smooth(ambient_space(t)) == false
@test toric_variety(calabi_yau_hypersurface(t)) == ambient_space(t)

isdefined(Main, :test_save_load_roundtrip) || include(
joinpath(Oscar.oscardir, "test", "Serialization", "test_save_load_roundtrip.jl")
)

mktempdir() do path
test_save_load_roundtrip(path, t) do loaded
@test tate_polynomial(loaded) == tate_polynomial(t)
@test tate_polynomial(t) == tate_polynomial(loaded)
@test tate_section_a1(t) == tate_section_a1(loaded)
@test tate_section_a2(t) == tate_section_a2(loaded)
@test tate_section_a3(t) == tate_section_a3(loaded)
Expand Down
4 changes: 4 additions & 0 deletions experimental/QuadFormAndIsom/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ end
Lf = integer_lattice_with_isometry(L; neg = true)
@test order_of_isometry(Lf) == -1

isdefined(Main, :test_save_load_roundtrip) || include(
joinpath(Oscar.oscardir, "test", "Serialization", "test_save_load_roundtrip.jl")
)

mktempdir() do path
test_save_load_roundtrip(path, Lf) do loaded
@test Lf == loaded
Expand Down
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
4 changes: 3 additions & 1 deletion test/Serialization/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Oscar

isdefined(Main, :test_save_load_roundtrip) ||
include(joinpath(Oscar.oscardir, "test", "Serialization", "test_save_load_roundtrip.jl"))

include("basic_types.jl")
include("PolyhedralGeometry.jl")
include("containers.jl")
Expand All @@ -13,4 +16,3 @@ include("TropicalGeometry.jl")
include("QuadForm.jl")
include("polymake/runtests.jl")
include("upgrades/runtests.jl")

45 changes: 45 additions & 0 deletions test/Serialization/test_save_load_roundtrip.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This code is needed for multiple test files that may end up on different workers.
# Thus, this needs to be conditionally included in each of these test files.

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: 0 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ end
Base.cumulative_compile_timing(true)
end

println("Making test list")

testlist = [

"Aqua.jl",
Expand Down