Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Visual regression tests #303

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
SymEngine = "123dc426-2d89-5057-bbad-38513e3affd8"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"

[targets]
test = ["DataFrames", "OffsetArrays", "SymEngine", "SparseArrays", "Test"]
test = ["DataFrames", "OffsetArrays", "SymEngine", "SparseArrays", "VisualRegressionTests", "Gtk", "Test"]
7 changes: 5 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
callshow=true,
open=true,
dpi=DEFAULT_DPI[],
transparent=true,
kw...
)
ext = "png"
Expand All @@ -154,11 +155,13 @@
# prefer tex -> pdf -> png instead
if convert === :gs
aux_mime = MIME("application/pdf")
cmd = `gs -sDEVICE=pngalpha -dTextAlphaBits=4 -r$dpi -o $name.$ext $aux_name.pdf`
device = transparent ? "pngalpha" : "png16m"
cmd = `gs -sDEVICE=$device -dTextAlphaBits=4 -r$dpi -o $name.$ext $aux_name.pdf`
elseif convert === :dvipng
aux_mime = MIME("application/x-dvi")
background = transparent ? "Transparent" : "white"

Check warning on line 162 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L162

Added line #L162 was not covered by tests
deb = debug ? [] : ["-q"]
cmd = `dvipng $(deb...) -bg Transparent -D $dpi -T tight $aux_name.dvi -o $name.$ext`
cmd = `dvipng $(deb...) -bg $background -D $dpi -T tight $aux_name.dvi -o $name.$ext`

Check warning on line 164 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L164

Added line #L164 was not covered by tests
else
error("$convert program not understood")
end
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ using Latexify
using LaTeXStrings
using Test

is_ci() = parse(Bool, get(ENV, "CI", "false"))

# Run tests

if ~is_ci() || Sys.islinux()
# Tests that for some reason don't run on Mac or Windows CI go here
@testset "visual regression tests" begin include("visualregression_tests.jl") end
end
@testset "macro test" begin include("macros.jl") end
@testset "recipe test" begin include("recipe_test.jl") end
@testset "latexify tests" begin include("latexify_test.jl") end
Expand Down
Binary file added test/visualreferences/ket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/visualreferences/simpleequation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/visualreferences/table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions test/visualregression_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Latexify, VisualRegressionTests
if ~is_ci()
using Gtk
end

function latexify_VRT(filename, args...; kwargs...)
testfun(fname) = render(latexify(args...; kwargs...), MIME"image/png"(); name=replace(fname, r".png$"=>""), transparent=false)
@visualtest testfun joinpath("visualreferences", filename) ~is_ci() 0.01
end

latexify_VRT("simpleequation.png", :(x^2-2y_a*exp(3)∈[1,2,3]); cdot=false)
latexify_VRT("table.png", hcat([1,2,3], [4,5,6], [7;8;9]); env=:table, head=["a" "b" "c"])

struct Ket{T}
x::T
end
@latexrecipe function f(x::Ket)
return Expr(:latexifymerge, "\\left|", x.x, "\\right>")
end
latexify_VRT("ket.png", :($(Ket(:a)) + $(Ket(:b))))
Loading