From 2c9043940f108eded4a8532e05015f6778538e18 Mon Sep 17 00:00:00 2001 From: David Gustavsson Date: Wed, 12 Oct 2022 14:48:14 +0200 Subject: [PATCH] Revert extraneous change, improve tests --- RecipesPipeline/src/type_recipe.jl | 1 - test/runtests.jl | 1 + test/test_unitful.jl | 20 ++++++++++---------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/RecipesPipeline/src/type_recipe.jl b/RecipesPipeline/src/type_recipe.jl index 6ea213205..d60a6e9b4 100644 --- a/RecipesPipeline/src/type_recipe.jl +++ b/RecipesPipeline/src/type_recipe.jl @@ -21,7 +21,6 @@ function _apply_type_recipe(plotattributes, v, letter) rdvec = RecipesBase.apply_recipe(plotattributes, typeof(v), v) warn_on_recipe_aliases!(plotattributes[:plot_object], plotattributes, :type, v) postprocess_axis_args!(plt, plotattributes, letter) - isnothing(rdvec) && return nothing return rdvec[1].args[1] end diff --git a/test/runtests.jl b/test/runtests.jl index 9f7992769..75d3a6f7b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,5 @@ import Unitful: m, s, cm, DimensionError +import Plots.UnitfulRecipes: getaxisunit import Plots: PLOTS_SEED, Plot, with import GeometryBasics import ImageMagick diff --git a/test/test_unitful.jl b/test/test_unitful.jl index 5753dcd24..5f8619601 100644 --- a/test/test_unitful.jl +++ b/test/test_unitful.jl @@ -7,7 +7,7 @@ xseries(pl, idx = length(pl.series_list)) = pl.series_list[idx].plotattributes[: yseries(pl, idx = length(pl.series_list)) = pl.series_list[idx].plotattributes[:y] zseries(pl, idx = length(pl.series_list)) = pl.series_list[idx].plotattributes[:z] -testfile = tempname() * ".png" +forcedraw(pl) = savefig(pl, tempname() * ".png") macro isplot(ex) # @isplot macro to streamline tests :(@test $(esc(ex)) isa Plot) @@ -41,6 +41,7 @@ end @testset "yunit" begin @test yguide(plot(y, yunit = cm)) == "cm" @test yseries(plot(y, yunit = cm)) ≈ ustrip.(cm, y) + @test getaxisunit(plot(y, yunit = cm).subplots[1][:yaxis]) == cm end @testset "ylims" begin # Using all(lims .≈ lims) because of uncontrolled type conversions? @@ -52,7 +53,7 @@ end @test_throws DimensionError begin pl = plot(y) plot!(pl; ylims = (-1s, 5s)) - savefig(pl, testfile) + forcedraw(pl) end end @@ -62,15 +63,15 @@ end pl = plot(y; ylims = encompassing_ylims, yticks = (1:5)m) @test compare_yticks(pl, 1:5) pl = plot(y; ylims = encompassing_ylims, yticks = [1cm, 3cm]) - savefig(pl, testfile) + forcedraw(pl) @test compare_yticks(pl, [0.01, 0.03]) pl = plot!(; ylims = encompassing_ylims, yticks = [-1cm, 4cm]) - savefig(pl, testfile) + forcedraw(pl) @test compare_yticks(pl, [-0.01, 0.04]) @test_throws DimensionError begin pl = plot(y) plot!(pl; yticks = (1:5)s) - savefig(pl, testfile) + forcedraw(pl) end end @@ -337,19 +338,18 @@ end @testset "Aspect ratio" begin pl = plot((1:10)u"m", (1:10)u"dm"; aspect_ratio = :equal) - savefig(pl, testfile) # Force a render, to make it evaluate aspect ratio + forcedraw(pl) @test abs(-(ylims(pl)...)) > 50 plot!(pl, (3:4)u"m", (4:5)u"m") @test first(pl.subplots)[:aspect_ratio] == 1 // 10 # This is what "equal" means when yunit==xunit/10 pl = plot((1:10)u"m", (1:10)u"dm"; aspect_ratio = 2) - savefig(pl, testfile) + forcedraw(pl) @test 25 < abs(-(ylims(pl)...)) < 50 pl = plot((1:10)u"m", (1:10)u"s"; aspect_ratio = 1u"m/s") - savefig(pl, testfile) + forcedraw(pl) @test 7.5 < abs(-(ylims(pl)...)) < 12.5 - @test_throws DimensionError savefig( + @test_throws DimensionError forcedraw( plot((1:10)u"m", (1:10)u"s"; aspect_ratio = :equal), - testfile, ) end