From c84c7ffe6d2b5e538f89b18d58dfdf4d7f3f0318 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Tue, 29 Nov 2022 13:56:42 +0100 Subject: [PATCH] enhance diagnostics --- src/Plots.jl | 2 +- src/backends.jl | 21 +++++++++++++++++--- test/test_axes.jl | 2 +- test/test_backends.jl | 46 +++++++++++++++++++++---------------------- 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index 089861de85..4719ff81e3 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -18,7 +18,7 @@ function _check_compat(sim::Module) haskey(_plots_compats, sim_str) || return nothing be_v = Pkg.Types.read_project(joinpath(Base.pkgdir(sim), "Project.toml")).version be_c = _plots_compats[sim_str] - if be_c isa String # julia 1.6 + if be_c isa String # julia 1.6 if !(be_v in Pkg.Types.semver_spec(be_c)) @warn "$sim $be_v is not compatible with this version of Plots. The declared compatibility is $(be_c)." end diff --git a/src/backends.jl b/src/backends.jl index 6379281f85..21340e6eab 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -144,9 +144,24 @@ set_backend!(; kw...) = set_preferences!(Plots, "backend" => nothing; kw...) set_backend!(backend::Union{AbstractString,Symbol}; kw...) = set_preferences!(Plots, "backend" => lowercase(string(backend)); kw...) -function diagnostics() - from = haskey(ENV, "PLOTS_DEFAULT_BACKEND") ? "environment variable" : "`Preferences`" - @info "selected `Plots` backend: $(backend()), from $from" _current_plots_version +function diagnostics(io::IO=stdout) + from = if has_preference(Plots, "backend") + "`Preferences`" + elseif haskey(ENV, "PLOTS_DEFAULT_BACKEND") + "environment variable" + else + "fallback" + end + if (be = backend_name()) !== :none + be_name = string(backend_package_name(be)) + @info "selected `Plots` backend: $be_name, from $from" + Pkg.status( + ["Plots", "RecipesBase", "RecipesPipeline", be_name]; + mode = Pkg.PKGMODE_MANIFEST, io + ) + else + @info "no `Plots` backends currently initialized" + end nothing end diff --git a/test/test_axes.jl b/test/test_axes.jl index 543516e7a3..7a1eb0d95c 100644 --- a/test/test_axes.jl +++ b/test/test_axes.jl @@ -244,7 +244,7 @@ end else length(minor_ticks) end - display(pl) + show(devnull, pl) @test n_minor_ticks == n_expected_minor_ticks end end diff --git a/test/test_backends.jl b/test/test_backends.jl index 183bab1e24..a54e231d59 100644 --- a/test/test_backends.jl +++ b/test/test_backends.jl @@ -128,32 +128,38 @@ end Plots.set_backend!(:gaston; force = true) @test Plots.load_default_backend() == Plots.GastonBackend() + @test_logs (:info, r".*Preferences") Plots.diagnostics(devnull) proc = ``` $(Base.julia_cmd()) -e " - ENV[\"PLOTS_PRECOMPILE\"] = false - using Pkg - Pkg.activate(; temp = true) - Pkg.develop(; path = \"$(escape_string(pkgdir(Plots)))\") + using Pkg; io = devnull + Pkg.activate(; temp = true, io) + Pkg.develop(; path = \"$(escape_string(pkgdir(Plots)))\", io) + withenv(\"PLOTS_PRECOMPILE\" => false) do using Plots, Test + Plots.diagnostics(io) @test backend() == Plots.GastonBackend() + end "``` |> run @test success(proc) - Plots.set_backend!(; force = true) + Plots.set_backend!(; force = true) # clear `Preferences` key - @test_logs (:warn, r".*is not a supported backend") withenv( - "PLOTS_DEFAULT_BACKEND" => "invalid", - ) do - Plots.load_default_backend() + withenv("PLOTS_DEFAULT_BACKEND" => "invalid") do + @test_logs (:warn, r".*is not a supported backend") Plots.load_default_backend() end @test_logs (:warn, r".*is not a supported backend") backend(:invalid) @test Plots.load_default_backend() == Plots.GRBackend() - @test withenv("PLOTS_DEFAULT_BACKEND" => "unicodeplots") do - Plots.load_default_backend() - end == Plots.UnicodePlotsBackend() + withenv("PLOTS_DEFAULT_BACKEND" => "unicodeplots") do + @test_logs (:info, r".*environment variable") Plots.diagnostics(devnull) + @test Plots.load_default_backend() == Plots.UnicodePlotsBackend() + end @test Plots.load_default_backend() == Plots.GRBackend() + @test Plots.backend_package_name() == :GR + @test Plots.backend_name() === :gr + + @test_logs (:info, r".*fallback") Plots.diagnostics(devnull) end @testset "UnicodePlots" begin @@ -210,17 +216,11 @@ end # NOTE: use `ENV["VISUAL_REGRESSION_TESTS_AUTO"] = true;` to automatically replace reference images @test backend() == Plots.GRBackend() @test backend_name() === :gr - withenv("PLOTS_TEST" => true, "GKSwstype" => "nul") do - @static if haskey(ENV, "APPVEYOR") - @info "Skipping GR image comparison tests on AppVeyor" - else - image_comparison_facts( - :gr, - tol = PLOTS_IMG_TOL, - skip = vcat(Plots._backend_skips[:gr], blacklist), - ) - end - end + image_comparison_facts( + :gr, + tol = PLOTS_IMG_TOL, + skip = vcat(Plots._backend_skips[:gr], blacklist), + ) end end