Merge pull request #2188 from daschw/tests2
Simplify adding new test imgages via PlotReferenceImages.jl
This commit is contained in:
commit
2c3bffaf76
17
.travis.yml
17
.travis.yml
@ -6,10 +6,14 @@ os:
|
|||||||
julia:
|
julia:
|
||||||
- 1.1
|
- 1.1
|
||||||
- nightly
|
- nightly
|
||||||
|
|
||||||
matrix:
|
addons:
|
||||||
allow_failures:
|
apt:
|
||||||
- julia: nightly
|
packages:
|
||||||
|
- at-spi2-core
|
||||||
|
- libgtk-3-dev
|
||||||
|
- xauth
|
||||||
|
- xvfb
|
||||||
|
|
||||||
sudo: required
|
sudo: required
|
||||||
before_install:
|
before_install:
|
||||||
@ -18,3 +22,8 @@ before_install:
|
|||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email: true
|
email: true
|
||||||
|
|
||||||
|
script:
|
||||||
|
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
|
||||||
|
- if [[ `uname` = "Linux" ]]; then TESTCMD="xvfb-run julia"; else TESTCMD="julia"; fi
|
||||||
|
- $TESTCMD -e 'using Pkg; Pkg.build(); Pkg.test(coverage=true)'
|
||||||
|
|||||||
@ -41,17 +41,18 @@ julia = "≥ 1.0.0"
|
|||||||
|
|
||||||
[extras]
|
[extras]
|
||||||
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
|
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
|
||||||
|
GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
|
||||||
|
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"
|
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
|
||||||
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 = ["FileIO", "GeometryTypes", "Gtk", "ImageMagick", "Images", "LaTeXStrings", "LibGit2", "Random", "RDatasets", "StatsPlots", "Test", "UnicodePlots", "VisualRegressionTests"]
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
module Plots
|
module Plots
|
||||||
|
|
||||||
_current_plots_version = v"0.26.1"
|
const _current_plots_version = VersionNumber(split(first(filter(line -> occursin("version", line), readlines(normpath(@__DIR__, "..", "Project.toml")))), "\"")[2])
|
||||||
|
|
||||||
using Reexport
|
using Reexport
|
||||||
|
|
||||||
|
|||||||
@ -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)]
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -461,7 +461,7 @@ _animation_examples = [2, 30]
|
|||||||
_backend_skips = Dict(
|
_backend_skips = Dict(
|
||||||
:gr => [25, 30],
|
:gr => [25, 30],
|
||||||
:pyplot => [25, 30],
|
:pyplot => [25, 30],
|
||||||
:plotlyjs => [2, 21, 25, 30, 31],
|
:plotlyjs => [2, 21, 24, 25, 30, 31],
|
||||||
:pgfplots => [2, 5, 6, 10, 16, 20, 22, 23, 25, 28, 30],
|
:pgfplots => [2, 5, 6, 10, 16, 20, 22, 23, 25, 28, 30],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -1,40 +1,72 @@
|
|||||||
|
import ImageMagick
|
||||||
using VisualRegressionTests
|
using VisualRegressionTests
|
||||||
using Plots
|
using Plots
|
||||||
using Random
|
using Random
|
||||||
using BinaryProvider
|
|
||||||
using Test
|
using Test
|
||||||
using FileIO
|
using FileIO
|
||||||
|
using Gtk
|
||||||
|
using LibGit2
|
||||||
using GeometryTypes
|
using GeometryTypes
|
||||||
|
|
||||||
|
reference_dir(args...) = joinpath(homedir(), ".julia", "dev", "PlotReferenceImages", args...)
|
||||||
|
|
||||||
|
function reference_file(backend, i, version)
|
||||||
|
refdir = reference_dir("Plots", string(backend))
|
||||||
|
fn = "ref$i.png"
|
||||||
|
versions = sort(VersionNumber.(readdir(refdir)), rev = true)
|
||||||
|
|
||||||
|
reffn = joinpath(refdir, string(version), fn)
|
||||||
|
for v in versions
|
||||||
|
tmpfn = joinpath(refdir, string(v), fn)
|
||||||
|
if isfile(tmpfn)
|
||||||
|
reffn = tmpfn
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return reffn
|
||||||
|
end
|
||||||
|
|
||||||
|
reference_path(backend, version) = reference_dir("Plots", string(backend), string(version))
|
||||||
|
|
||||||
|
if !isdir(reference_dir())
|
||||||
|
mkpath(reference_dir())
|
||||||
|
LibGit2.clone("https://github.com/JuliaPlots/PlotReferenceImages.jl.git", reference_dir())
|
||||||
|
end
|
||||||
|
|
||||||
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") == "true"
|
||||||
|
img_tol = is_ci() ? 10e-2 : 10e-2
|
||||||
|
|
||||||
@testset "GR" begin
|
@testset "Backends" begin
|
||||||
ENV["PLOTS_TEST"] = "true"
|
|
||||||
ENV["GKSwstype"] = "100"
|
|
||||||
@test gr() == Plots.GRBackend()
|
|
||||||
@test backend() == Plots.GRBackend()
|
|
||||||
|
|
||||||
@static if Sys.islinux()
|
@testset "GR" begin
|
||||||
image_comparison_facts(:gr, tol=img_tol, skip = [25, 30])
|
ENV["PLOTS_TEST"] = "true"
|
||||||
|
ENV["GKSwstype"] = "100"
|
||||||
|
@test gr() == Plots.GRBackend()
|
||||||
|
@test backend() == Plots.GRBackend()
|
||||||
|
|
||||||
|
@static if Sys.islinux()
|
||||||
|
image_comparison_facts(:gr, tol=img_tol, skip = Plots._backend_skips[:gr])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
@testset "UnicodePlots" begin
|
||||||
|
@test unicodeplots() == Plots.UnicodePlotsBackend()
|
||||||
|
@test backend() == Plots.UnicodePlotsBackend()
|
||||||
|
|
||||||
@testset "UnicodePlots" begin
|
# lets just make sure it runs without error
|
||||||
@test unicodeplots() == Plots.UnicodePlotsBackend()
|
p = plot(rand(10))
|
||||||
@test backend() == Plots.UnicodePlotsBackend()
|
@test isa(p, Plots.Plot) == true
|
||||||
|
@test isa(display(p), Nothing) == true
|
||||||
|
p = bar(randn(10))
|
||||||
|
@test isa(p, Plots.Plot) == true
|
||||||
|
@test isa(display(p), Nothing) == true
|
||||||
|
end
|
||||||
|
|
||||||
# lets just make sure it runs without error
|
|
||||||
p = plot(rand(10))
|
|
||||||
@test isa(p, Plots.Plot) == true
|
|
||||||
@test isa(display(p), Nothing) == true
|
|
||||||
p = bar(randn(10))
|
|
||||||
@test isa(p, Plots.Plot) == true
|
|
||||||
@test isa(display(p), Nothing) == true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "Axes" begin
|
@testset "Axes" begin
|
||||||
@ -97,6 +129,6 @@ end
|
|||||||
[(missing,missing)], [(missing,missing,missing),("a","b","c")])
|
[(missing,missing)], [(missing,missing,missing),("a","b","c")])
|
||||||
for z in zipped
|
for z in zipped
|
||||||
@test isequal(collect(zip(Plots.unzip(z)...)), z)
|
@test isequal(collect(zip(Plots.unzip(z)...)), z)
|
||||||
@test isequal(collect(zip(Plots.unzip(Point.(z))...)), z)
|
@test isequal(collect(zip(Plots.unzip(GeometryTypes.Point.(z))...)), z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user