|
423 | 423 | ) |
424 | 424 | @test fig_no_moments !== nothing |
425 | 425 | safe_rm(no_cm_path) |
| 426 | + |
| 427 | + # Tests for save_plot function |
| 428 | + if backend == "Makie" |
| 429 | + body_aero = create_body_aero() |
| 430 | + fig = plot_geometry( |
| 431 | + body_aero, |
| 432 | + "save_plot_test"; |
| 433 | + is_save=false, |
| 434 | + is_show=false) |
| 435 | + @test fig isa Figure |
| 436 | + |
| 437 | + save_test_dir = tempdir() |
| 438 | + |
| 439 | + # Test 1: save_plot with explicit data_type (".png") |
| 440 | + VortexStepMethod.save_plot(fig, save_test_dir, "test_explicit_png", data_type=".png") |
| 441 | + @test isfile(joinpath(save_test_dir, "test_explicit_png.png")) |
| 442 | + safe_rm(joinpath(save_test_dir, "test_explicit_png.png")) |
| 443 | + |
| 444 | + # Test 2: save_plot with explicit data_type (".pdf") |
| 445 | + VortexStepMethod.save_plot(fig, save_test_dir, "test_explicit_pdf", data_type=".pdf") |
| 446 | + @test isfile(joinpath(save_test_dir, "test_explicit_pdf.pdf")) |
| 447 | + safe_rm(joinpath(save_test_dir, "test_explicit_pdf.pdf")) |
| 448 | + |
| 449 | + # Test 3: save_plot with data_type=nothing (backend-aware detection) |
| 450 | + VortexStepMethod.save_plot(fig, save_test_dir, "test_backend_aware", data_type=nothing) |
| 451 | + cairo_loaded = any(m -> nameof(m) == :CairoMakie, values(Base.loaded_modules)) |
| 452 | + expected_ext = cairo_loaded ? ".pdf" : ".png" |
| 453 | + @test isfile(joinpath(save_test_dir, "test_backend_aware" * expected_ext)) |
| 454 | + safe_rm(joinpath(save_test_dir, "test_backend_aware" * expected_ext)) |
| 455 | + |
| 456 | + # Test 4: save_plot with title containing spaces (should be sanitized to underscores) |
| 457 | + VortexStepMethod.save_plot(fig, save_test_dir, "test with spaces", data_type=".png") |
| 458 | + @test isfile(joinpath(save_test_dir, "test_with_spaces.png")) |
| 459 | + safe_rm(joinpath(save_test_dir, "test_with_spaces.png")) |
| 460 | + |
| 461 | + # Test 5: save_plot with title containing percent signs (should be sanitized to "pct") |
| 462 | + VortexStepMethod.save_plot(fig, save_test_dir, "test%efficiency", data_type=".png") |
| 463 | + @test isfile(joinpath(save_test_dir, "testpctefficiency.png")) |
| 464 | + safe_rm(joinpath(save_test_dir, "testpctefficiency.png")) |
| 465 | + |
| 466 | + # Test 6: save_plot with title containing both spaces and percent signs |
| 467 | + VortexStepMethod.save_plot(fig, save_test_dir, "test %efficiency metric", data_type=".png") |
| 468 | + @test isfile(joinpath(save_test_dir, "test_pctefficiency_metric.png")) |
| 469 | + safe_rm(joinpath(save_test_dir, "test_pctefficiency_metric.png")) |
| 470 | + |
| 471 | + # Test 7: save_plot creates directory if it doesn't exist |
| 472 | + nested_dir = joinpath(save_test_dir, "nested_save_plot_dir") |
| 473 | + !isdir(nested_dir) && @test !isdir(nested_dir) |
| 474 | + VortexStepMethod.save_plot(fig, nested_dir, "test_nested_dir", data_type=".png") |
| 475 | + @test isdir(nested_dir) |
| 476 | + @test isfile(joinpath(nested_dir, "test_nested_dir.png")) |
| 477 | + safe_rm(joinpath(nested_dir, "test_nested_dir.png")) |
| 478 | + rm(nested_dir; force=true) |
| 479 | + |
| 480 | + # Test 8: save_plot raises error when save_path is nothing |
| 481 | + @test_throws ArgumentError VortexStepMethod.save_plot(fig, nothing, "test_title", data_type=".png") |
| 482 | + end |
426 | 483 | end |
427 | 484 | nothing |
0 commit comments