use PlotReferenceImages Julia Package for tests

This commit is contained in:
Daniel Schwabeneder 2019-06-14 23:29:46 +02:00
parent cd1ee47ace
commit f22abb8508
4 changed files with 15 additions and 73 deletions

View File

@ -40,17 +40,18 @@ julia = "≥ 1.0.0"
[extras] [extras]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PlotReferenceImages = "c5e800db-1e6b-5f72-915a-308d267b7a19"
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b" RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92" VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
[targets] [targets]
test = ["BinaryProvider", "Pkg", "Test", "Random", "StatsPlots", "VisualRegressionTests", "LaTeXStrings", "Images", "ImageMagick", "RDatasets", "FileIO", "UnicodePlots"] test = ["Pkg", "Test", "Random", "StatsPlots", "VisualRegressionTests", "LaTeXStrings", "Images", "ImageMagick", "RDatasets", "FileIO", "Gtk", "UnicodePlots", "PlotReferenceImages"]

View File

@ -238,12 +238,12 @@ build with the method `text(string, attr...)`, which wraps font and color attrib
""", """,
[:(begin [:(begin
y = rand(10) y = rand(10)
plot(y, annotations = (3,y[3],text("this is #3",:left)), leg=false) plot(y, annotations = (3,y[3], Plots.text("this is #3",:left)), leg=false)
annotate!([(5, y[5], text("this is #5",16,:red,:center)), annotate!([(5, y[5], Plots.text("this is #5",16,:red,:center)),
(10, y[10], text("this is #10",:right,20,"courier"))]) (10, y[10], Plots.text("this is #10",:right,20,"courier"))])
scatter!(range(2, stop=8, length=6), rand(6), marker=(50,0.2,:orange), scatter!(range(2, stop=8, length=6), rand(6), marker=(50,0.2,:orange),
series_annotations = ["series","annotations","map","to","series", series_annotations = ["series","annotations","map","to","series",
text("data",:green)]) Plots.text("data",:green)])
end)] end)]
), ),

View File

@ -1,34 +1,6 @@
import Plots._current_plots_version import Plots._current_plots_version
# Taken from MakieGallery function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = !is_ci(), sigma = [1,1], tol = 1e-2)
"""
Downloads the reference images from ReferenceImages for a specific version
"""
function download_reference(version = v"0.0.1")
download_dir = abspath(@__DIR__, "reference_images")
isdir(download_dir) || mkpath(download_dir)
tarfile = joinpath(download_dir, "reference_images.zip")
url = "https://github.com/JuliaPlots/PlotReferenceImages.jl/archive/v$(version).tar.gz"
refpath = joinpath(download_dir, "PlotReferenceImages.jl-$(version)")
if !isdir(refpath) # if not yet downloaded
@info "downloading reference images for version $version"
download(url, tarfile)
BinaryProvider.unpack(tarfile, download_dir)
# check again after download
if !isdir(refpath)
error("Something went wrong while downloading reference images. Plots can't be compared to references")
else
rm(tarfile, force = true)
end
else
@info "using reference images for version $version (already downloaded)"
end
refpath
end
const ref_image_dir = download_reference()
function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = isinteractive(), sigma = [1,1], tol = 1e-2)
Plots._debugMode.on = debug Plots._debugMode.on = debug
example = Plots._examples[idx] example = Plots._examples[idx]
Plots.theme(:default) Plots.theme(:default)
@ -39,36 +11,9 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is
# ensure consistent results # ensure consistent results
Random.seed!(1234) Random.seed!(1234)
# reference image directory setup
refdir = joinpath(ref_image_dir, "Plots", string(pkg))
fn = "ref$idx.png" fn = "ref$idx.png"
reffn = reference_file(pkg, idx, _current_plots_version)
# firgure out version info newfn = joinpath(reference_path(pkg, _current_plots_version), fn)
vns = filter(x->x[1] != '.', readdir(refdir))
versions = sort(VersionNumber.(vns), rev = true)
versions = filter(v -> v <= _current_plots_version, versions)
# @show refdir fn versions
newdir = joinpath(refdir, string(_current_plots_version))
newfn = joinpath(newdir, fn)
# figure out which reference file we should compare to, by finding the highest versioned file
reffn = nothing
for v in versions
tmpfn = joinpath(refdir, string(v), fn)
if isfile(tmpfn)
reffn = tmpfn
break
end
end
# now we have the fn (if any)... do the comparison
# @show reffn
if reffn == nothing
reffn = newfn
end
# @show reffn
# return
# test function # test function
func = (fn, idx) -> begin func = (fn, idx) -> begin
@ -78,13 +23,6 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = false, popup = is
png(fn) png(fn)
end end
# try
# run(`mkdir -p $newdir`)
# catch err
# display(err)
# end
# # reffn = joinpath(refdir, "ref$idx.png")
# the test # the test
vtest = VisualTest(func, reffn, idx) vtest = VisualTest(func, reffn, idx)
test_images(vtest, popup=popup, sigma=sigma, tol=tol, newfn = newfn) test_images(vtest, popup=popup, sigma=sigma, tol=tol, newfn = newfn)

View File

@ -1,15 +1,18 @@
using VisualRegressionTests using VisualRegressionTests
using Plots using Plots
using Random using Random
using BinaryProvider
using Test using Test
using FileIO using FileIO
using PlotReferenceImages
using Gtk
include("imgcomp.jl") include("imgcomp.jl")
# don't actually show the plots # don't actually show the plots
Random.seed!(1234) Random.seed!(1234)
default(show=false, reuse=true) default(show=false, reuse=true)
img_tol = isinteractive() ? 1e-2 : 10e-2 is_ci() = get(ENV, "CI", false)
img_tol = is_ci() ? 10e-2 : 1e-2
@testset "GR" begin @testset "GR" begin
ENV["PLOTS_TEST"] = "true" ENV["PLOTS_TEST"] = "true"