working on test framework
This commit is contained in:
parent
8208f6947f
commit
866ac9fb72
@ -18,21 +18,13 @@ type PlotExample
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function fakedata(sz...)
|
|
||||||
y = zeros(sz...)
|
|
||||||
for r in 2:size(y,1)
|
|
||||||
y[r,:] = 0.9 * y[r-1,:] + randn(size(y,2))'
|
|
||||||
end
|
|
||||||
y
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# the examples we'll run for each
|
# the examples we'll run for each
|
||||||
const examples = PlotExample[
|
const examples = PlotExample[
|
||||||
PlotExample("Lines",
|
PlotExample("Lines",
|
||||||
"A simple line plot of the columns.",
|
"A simple line plot of the columns.",
|
||||||
[
|
[
|
||||||
:(plot(fakedata(50,5), w=3))
|
:(plot(Plots.fakedata(50,5), w=3))
|
||||||
]),
|
]),
|
||||||
PlotExample("Functions, adding data, and animations",
|
PlotExample("Functions, adding data, and animations",
|
||||||
"Plot multiple functions. You can also put the function first, or use the form `plot(f, xmin, xmax)` where f is a Function or AbstractVector{Function}.\n\nGet series data: `x, y = plt[i]`. Set series data: `plt[i] = (x,y)`. Add to the series with `push!`/`append!`.\n\nEasily build animations. (`convert` or `ffmpeg` must be available to generate the animation.) Use command `gif(anim, filename, fps=15)` to save the animation.",
|
"Plot multiple functions. You can also put the function first, or use the form `plot(f, xmin, xmax)` where f is a Function or AbstractVector{Function}.\n\nGet series data: `x, y = plt[i]`. Set series data: `plt[i] = (x,y)`. Add to the series with `push!`/`append!`.\n\nEasily build animations. (`convert` or `ffmpeg` must be available to generate the animation.) Use command `gif(anim, filename, fps=15)` to save the animation.",
|
||||||
@ -134,12 +126,12 @@ const examples = PlotExample[
|
|||||||
PlotExample("Adding to subplots",
|
PlotExample("Adding to subplots",
|
||||||
"Note here the automatic grid layout, as well as the order in which new series are added to the plots.",
|
"Note here the automatic grid layout, as well as the order in which new series are added to the plots.",
|
||||||
[
|
[
|
||||||
:(subplot(fakedata(100,10), n=4, palette=[:grays :blues :heat :lightrainbow], bg=[:orange :pink :darkblue :black]))
|
:(subplot(Plots.fakedata(100,10), n=4, palette=[:grays :blues :heat :lightrainbow], bg=[:orange :pink :darkblue :black]))
|
||||||
]),
|
]),
|
||||||
PlotExample("",
|
PlotExample("",
|
||||||
"",
|
"",
|
||||||
[
|
[
|
||||||
:(subplot!(fakedata(100,10)))
|
:(subplot!(Plots.fakedata(100,10)))
|
||||||
]),
|
]),
|
||||||
PlotExample("Open/High/Low/Close",
|
PlotExample("Open/High/Low/Close",
|
||||||
"Create an OHLC chart. Pass in a vector of OHLC objects as your `y` argument. Adjust the tick width with arg `markersize`.",
|
"Create an OHLC chart. Pass in a vector of OHLC objects as your `y` argument. Adjust the tick width with arg `markersize`.",
|
||||||
|
|||||||
28
src/utils.jl
28
src/utils.jl
@ -104,6 +104,18 @@ function sticksHack(; kw...)
|
|||||||
dLine, dScatter
|
dLine, dScatter
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function regressionXY(x, y)
|
||||||
|
# regress
|
||||||
|
β, α = [x ones(length(x))] \ y
|
||||||
|
|
||||||
|
# make a line segment
|
||||||
|
regx = [minimum(x), maximum(x)]
|
||||||
|
regy = β * regx + α
|
||||||
|
regx, regy
|
||||||
|
end
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
get_mod(v, idx::Int) = v[mod1(idx, length(v))]
|
get_mod(v, idx::Int) = v[mod1(idx, length(v))]
|
||||||
|
|
||||||
makevec(v::AVec) = v
|
makevec(v::AVec) = v
|
||||||
@ -162,16 +174,16 @@ Base.first(c::Colorant) = c
|
|||||||
sortedkeys(d::Dict) = sort(collect(keys(d)))
|
sortedkeys(d::Dict) = sort(collect(keys(d)))
|
||||||
|
|
||||||
|
|
||||||
function regressionXY(x, y)
|
function fakedata(sz...)
|
||||||
# regress
|
y = zeros(sz...)
|
||||||
β, α = [x ones(length(x))] \ y
|
for r in 2:size(y,1)
|
||||||
|
y[r,:] = 0.9 * y[r-1,:] + randn(size(y,2))'
|
||||||
# make a line segment
|
end
|
||||||
regx = [minimum(x), maximum(x)]
|
y
|
||||||
regy = β * regx + α
|
|
||||||
regx, regy
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ticksType{T<:Real,S<:Real}(ticks::@compat(Tuple{T,S})) = :limits
|
# ticksType{T<:Real,S<:Real}(ticks::@compat(Tuple{T,S})) = :limits
|
||||||
ticksType{T<:Real}(ticks::AVec{T}) = :ticks
|
ticksType{T<:Real}(ticks::AVec{T}) = :ticks
|
||||||
ticksType{T<:AVec,S<:AVec}(ticks::@compat(Tuple{T,S})) = :ticks_and_labels
|
ticksType{T<:AVec,S<:AVec}(ticks::@compat(Tuple{T,S})) = :ticks_and_labels
|
||||||
|
|||||||
@ -16,48 +16,75 @@ include("../docs/example_generation.jl")
|
|||||||
# plt
|
# plt
|
||||||
# end
|
# end
|
||||||
|
|
||||||
using Plots, Gtk.ShortNames
|
using Plots
|
||||||
|
import Images, Gtk, ImageMagick
|
||||||
|
|
||||||
function makeImageWidget(fn)
|
function makeImageWidget(fn)
|
||||||
img = @Image(fn)
|
img = Gtk.GtkImageLeaf(fn)
|
||||||
vbox = @Box(:v)
|
vbox = Gtk.GtkBoxLeaf(:v)
|
||||||
|
push!(vbox, Gtk.GtkLabelLeaf(fn))
|
||||||
push!(vbox, img)
|
push!(vbox, img)
|
||||||
show(img)
|
show(img)
|
||||||
vbox
|
vbox
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function replaceReferenceImage(tmpfn, reffn)
|
||||||
|
println("cp $tmpfn $reffn")
|
||||||
|
end
|
||||||
|
|
||||||
"Show a Gtk popup with both images and a confirmation whether we should replace the new image with the old one"
|
"Show a Gtk popup with both images and a confirmation whether we should replace the new image with the old one"
|
||||||
function isTempImageCorrect(tmpfn, reffn)
|
function compareToReferenceImage(tmpfn, reffn)
|
||||||
|
|
||||||
# add the images
|
# add the images
|
||||||
imgbox = @Box(:h)
|
imgbox = Gtk.GtkBoxLeaf(:h)
|
||||||
push!(imgbox, makeImageWidget(tmpfn))
|
push!(imgbox, makeImageWidget(tmpfn))
|
||||||
push!(imgbox, makeImageWidget(reffn))
|
push!(imgbox, makeImageWidget(reffn))
|
||||||
|
|
||||||
# add the buttons
|
# add the buttons
|
||||||
keepbtn = @Button("KEEP")
|
doNothingButton = Gtk.GtkButtonLeaf("Skip")
|
||||||
overwritebtn = @Button("OVERWRITE")
|
replaceReferenceButton = Gtk.GtkButtonLeaf("Replace reference image")
|
||||||
btnbox = @Box(:h)
|
btnbox = Gtk.GtkButtonBoxLeaf(:h)
|
||||||
push!(btnbox, keepbtn)
|
push!(btnbox, doNothingButton)
|
||||||
push!(btnbox, overwritebtn)
|
push!(btnbox, replaceReferenceButton)
|
||||||
|
|
||||||
# create the window
|
# create the window
|
||||||
box = @Box(:v)
|
box = Gtk.GtkBoxLeaf(:v)
|
||||||
push!(box, imgbox)
|
push!(box, imgbox)
|
||||||
push!(box, btnbox)
|
push!(box, btnbox)
|
||||||
w = @Window(@Frame(box))
|
win = Gtk.GtkWindowLeaf(Gtk.GtkFrameLeaf(box))
|
||||||
showall(w)
|
|
||||||
w
|
# we'll wait on this condition
|
||||||
|
c = Condition()
|
||||||
|
Gtk.on_signal_destroy((x...) -> notify(c), win)
|
||||||
|
|
||||||
|
Gtk.signal_connect(replaceReferenceButton, "clicked") do widget
|
||||||
|
replaceReferenceImage(tmpfn, reffn)
|
||||||
|
notify(c)
|
||||||
|
end
|
||||||
|
|
||||||
|
Gtk.signal_connect(doNothingButton, "clicked") do widget
|
||||||
|
notify(c)
|
||||||
|
end
|
||||||
|
|
||||||
|
# wait until a button is clicked, then close the window
|
||||||
|
Gtk.showall(win)
|
||||||
|
wait(c)
|
||||||
|
Gtk.destroy(win)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: use julia's Condition type and the wait() and notify() functions to initialize a Window, then wait() on a condition that
|
||||||
|
# is referenced in a button press callback (the button clicked callback will call notify() on that condition)
|
||||||
|
|
||||||
function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0,0], eps = 1e-3)
|
function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0,0], eps = 1e-3)
|
||||||
|
|
||||||
# first
|
# first
|
||||||
Plots._debugMode.on = debug
|
Plots._debugMode.on = debug
|
||||||
info("Testing plot: $pkg:$idx:$(examples[idx].header)")
|
info("Testing plot: $pkg:$idx:$(PlotExamples.examples[idx].header)")
|
||||||
backend(pkg)
|
backend(pkg)
|
||||||
backend()
|
backend()
|
||||||
|
|
||||||
|
info("here: ", PlotExamples.examples[idx].exprs)
|
||||||
map(eval, PlotExamples.examples[idx].exprs)
|
map(eval, PlotExamples.examples[idx].exprs)
|
||||||
|
|
||||||
# save the png
|
# save the png
|
||||||
@ -65,31 +92,42 @@ function image_comparison_tests(pkg::Symbol, idx::Int; debug = true, sigma = [0,
|
|||||||
png(tmpfn)
|
png(tmpfn)
|
||||||
|
|
||||||
# load the saved png
|
# load the saved png
|
||||||
tmpimg = imread(tmpfn)
|
tmpimg = Images.load(tmpfn)
|
||||||
|
|
||||||
# load the reference image
|
# reference image location
|
||||||
reffn = joinpath(Pkg.dir("Plots"), "test", "refimg", pkg, "$idx.png")
|
refdir = joinpath(Pkg.dir("Plots"), "test", "refimg", "v$(VERSION.major).$(VERSION.minor)", string(pkg))
|
||||||
refimg = imread(reffn)
|
try
|
||||||
|
mkdir(refdir)
|
||||||
|
catch err
|
||||||
|
display(err)
|
||||||
|
end
|
||||||
|
reffn = joinpath(refdir, "ref$idx.png")
|
||||||
|
|
||||||
# run the test
|
|
||||||
# NOTE: sigma is a 2-length vector with x/y values for the number of pixels
|
|
||||||
# to blur together when comparing images
|
|
||||||
try
|
try
|
||||||
|
|
||||||
|
info("Comparing $tmpfn to reference $reffn")
|
||||||
|
|
||||||
|
# load the reference image
|
||||||
|
refimg = Images.load(reffn)
|
||||||
|
|
||||||
# run the comparison test... a difference will throw an error
|
# run the comparison test... a difference will throw an error
|
||||||
@test_approx_eq_sigma_eps(tmpimg, refimg, sigma, eps)
|
# NOTE: sigma is a 2-length vector with x/y values for the number of pixels
|
||||||
|
# to blur together when comparing images
|
||||||
|
Images.@test_approx_eq_sigma_eps(tmpimg, refimg, sigma, eps)
|
||||||
|
|
||||||
catch ex
|
catch ex
|
||||||
if isinteractive()
|
if isinteractive()
|
||||||
|
|
||||||
# if we're in interactive mode, open a popup and give us a chance to examine the images
|
# if we're in interactive mode, open a popup and give us a chance to examine the images
|
||||||
if isTempImageCorrect(tmpfn, reffn)
|
compareToReferenceImage(tmpfn, reffn)
|
||||||
return
|
return
|
||||||
end
|
|
||||||
|
else
|
||||||
|
|
||||||
|
# if we rejected the image, or if we're in automated tests, throw the error
|
||||||
|
rethrow(ex)
|
||||||
end
|
end
|
||||||
|
|
||||||
# if we rejected the image, or if we're in automated tests, throw the error
|
|
||||||
throw(ex)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user