Skip to content

Commit 5d41ba4

Browse files
committed
Improve test
1 parent 8f19fd3 commit 5d41ba4

1 file changed

Lines changed: 16 additions & 24 deletions

File tree

test/plotting/test_plotting.jl

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ end
558558
is_show=false)
559559
@test fig isa Figure
560560

561+
active_backend_prefers_vector_output =
562+
getfield(makie_ext, :_active_backend_prefers_vector_output)
563+
561564
save_test_dir = tempdir()
562565

563566
# Test 1: save_plot with explicit data_type (".png")
@@ -571,31 +574,20 @@ end
571574
safe_rm(joinpath(save_test_dir, "test_explicit_pdf.pdf"))
572575

573576
# Test 3: save_plot with data_type=nothing (backend-aware detection)
574-
VortexStepMethod.save_plot(fig, save_test_dir, "test_backend_aware", data_type=nothing)
575-
backend_obj = Makie.current_backend()
576-
backend_name = if backend_obj isa Module
577-
nameof(backend_obj)
578-
elseif backend_obj isa DataType
579-
nameof(backend_obj)
580-
elseif Base.applicable(backend_obj)
581-
called_backend = try
582-
backend_obj()
583-
catch
584-
nothing
585-
end
586-
if called_backend isa Module
587-
nameof(called_backend)
588-
elseif called_backend isa DataType
589-
nameof(called_backend)
590-
else
591-
Symbol(string(something(called_backend, backend_obj)))
592-
end
593-
else
594-
Symbol(string(backend_obj))
577+
backend_aware_dir = mktempdir()
578+
try
579+
VortexStepMethod.save_plot(fig, backend_aware_dir, "test_backend_aware", data_type=nothing)
580+
pdf_path = joinpath(backend_aware_dir, "test_backend_aware.pdf")
581+
png_path = joinpath(backend_aware_dir, "test_backend_aware.png")
582+
expected_ext = active_backend_prefers_vector_output(Makie) ? ".pdf" : ".png"
583+
584+
@test xor(isfile(pdf_path), isfile(png_path))
585+
@test isfile(joinpath(backend_aware_dir, "test_backend_aware" * expected_ext))
586+
finally
587+
safe_rm(joinpath(backend_aware_dir, "test_backend_aware.pdf"))
588+
safe_rm(joinpath(backend_aware_dir, "test_backend_aware.png"))
589+
rm(backend_aware_dir; force=true, recursive=true)
595590
end
596-
expected_ext = lowercase(String(backend_name)) == "cairomakie" ? ".pdf" : ".png"
597-
@test isfile(joinpath(save_test_dir, "test_backend_aware" * expected_ext))
598-
safe_rm(joinpath(save_test_dir, "test_backend_aware" * expected_ext))
599591

600592
# Test 4: save_plot with title containing spaces (should be sanitized to underscores)
601593
VortexStepMethod.save_plot(fig, save_test_dir, "test with spaces", data_type=".png")

0 commit comments

Comments
 (0)