Skip to content

Commit

Permalink
replace __init__ calls in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Sep 24, 2022
1 parent 8c8c233 commit c902e9d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
34 changes: 20 additions & 14 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,30 @@ _plots_defaults() =
Dict{Symbol,Any}()
end

function __init__()
function _plots_theme_defaults()
user_defaults = _plots_defaults()
if haskey(user_defaults, :theme)
theme(pop!(user_defaults, :theme); user_defaults...)
else
default(; user_defaults...)
end
end

function _plots_plotly_defaults()
if get(ENV, "PLOTS_HOST_DEPENDENCY_LOCAL", "false") == "true"
global plotly_local_file_path[] =
joinpath(@get_scratch!("plotly"), _plotly_min_js_filename)
isfile(plotly_local_file_path[]) || Downloads.download(
"https://cdn.plot.ly/$(_plotly_min_js_filename)",
plotly_local_file_path[],
)
use_local_plotlyjs[] = true
end
use_local_dependencies[] = use_local_plotlyjs[]
end

function __init__()
_plots_theme_defaults()

insert!(
Base.Multimedia.displays,
Expand Down Expand Up @@ -77,6 +94,8 @@ function __init__()
include(BACKEND_PATH_PLOTLYJS)
end

_plots_plotly_defaults()

@require PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee" begin
include(BACKEND_PATH_PYPLOT)
end
Expand All @@ -96,19 +115,6 @@ function __init__()
end
end

if get(ENV, "PLOTS_HOST_DEPENDENCY_LOCAL", "false") == "true"
global plotly_local_file_path[] =
joinpath(@get_scratch!("plotly"), _plotly_min_js_filename)
isfile(plotly_local_file_path[]) || Downloads.download(
"https://cdn.plot.ly/$(_plotly_min_js_filename)",
plotly_local_file_path[],
)

use_local_plotlyjs[] = true
end

use_local_dependencies[] = use_local_plotlyjs[]

@require ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" begin
if get(ENV, "PLOTS_IMAGE_IN_TERMINAL", "false") == "true" &&
ImageInTerminal.ENCODER_BACKEND[] == :Sixel
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Unitful: m, s, cm, DimensionError
import Plots: PLOTS_SEED, Plot, with
import GeometryBasics
import ImageMagick
Expand Down
7 changes: 2 additions & 5 deletions test/test_defaults.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Plots, Test
using Plots.Colors

const PLOTS_DEFAULTS = Dict(:theme => :wong2, :fontfamily => :palantino)
Plots.__init__()
Plots._plots_theme_defaults()

@testset "Loading theme" begin
pl = plot(1:5)
Expand All @@ -11,7 +8,7 @@ Plots.__init__()
end

empty!(PLOTS_DEFAULTS)
Plots.__init__()
Plots._plots_theme_defaults()

@testset "default" begin
default(fillrange = 0)
Expand Down
2 changes: 1 addition & 1 deletion test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end
@test Plots.plotly_local_file_path[] === nothing
temp = Plots.use_local_dependencies[]
withenv("PLOTS_HOST_DEPENDENCY_LOCAL" => true) do
Plots.__init__()
Plots._plots_plotly_defaults()
@test Plots.plotly_local_file_path[] isa String
@test isfile(Plots.plotly_local_file_path[])
@test Plots.use_local_dependencies[] = true
Expand Down
1 change: 0 additions & 1 deletion test/test_unitful.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Unitful: m, s, cm, DimensionError

# Some helper functions to access the subplot labels and the series inside each test plot
xguide(pl, idx = length(pl.subplots)) = pl.subplots[idx].attr[:xaxis].plotattributes[:guide]
Expand Down

0 comments on commit c902e9d

Please sign in to comment.