Skip to content

Commit

Permalink
enhance diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Nov 29, 2022
1 parent afbf205 commit c84c7ff
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions src/backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/test_axes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 23 additions & 23 deletions test/test_backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit c84c7ff

Please sign in to comment.