From 35addd2b505713b22dcb35be53e5abc2c8a3572e Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Mon, 11 Mar 2019 10:23:31 +0200 Subject: [PATCH] Fixes to option parsing, gadfly pdf, stripping header, add tests --- Project.toml | 4 +- src/Weave.jl | 9 +- src/config.jl | 29 +++-- src/display_methods.jl | 2 +- src/format.jl | 2 +- src/gadfly.jl | 10 +- src/pyplot.jl | 20 --- .../gadfly/gadfly_formats_test.md.pdf.github | 18 +++ .../gadfly/gadfly_formats_test.md.png.github | 18 +++ .../gadfly/gadfly_formats_test.md.png.pandoc | 23 ++++ .../gadfly/gadfly_formats_test.md.svg.github | 18 +++ .../gadfly/gadfly_formats_test.tex.pdf.tex | 23 ++++ .../gadfly/gadfly_formats_test.tex.png.tex | 23 ++++ test/documents/gadfly_formats_test.jnw | 19 +++ test/documents/gadfly_formats_test.txt | 29 ----- .../gadfly_formats_test_jssvg_ref.md | 53 -------- test/documents/gadfly_formats_test_mmd_ref.md | 67 ---------- .../gadfly_formats_test_pandoc_ref.md | 58 --------- test/documents/gadfly_formats_test_ps_ref.tex | 52 -------- test/documents/gadfly_formats_test_ref.rst | 76 ----------- test/documents/gadfly_formats_test_ref.tex | 52 -------- test/documents/gadfly_formats_test_svg_ref.md | 58 --------- .../gadfly_formats_test_tikz_ref.tex | 52 -------- test/documents/gadfly_markdown_test_ref.md | 80 ------------ test/gadfly_formats.jl | 121 ++++++++++-------- test/runtests.jl | 7 +- 26 files changed, 250 insertions(+), 673 deletions(-) delete mode 100644 src/pyplot.jl create mode 100644 test/documents/gadfly/gadfly_formats_test.md.pdf.github create mode 100644 test/documents/gadfly/gadfly_formats_test.md.png.github create mode 100644 test/documents/gadfly/gadfly_formats_test.md.png.pandoc create mode 100644 test/documents/gadfly/gadfly_formats_test.md.svg.github create mode 100644 test/documents/gadfly/gadfly_formats_test.tex.pdf.tex create mode 100644 test/documents/gadfly/gadfly_formats_test.tex.png.tex create mode 100644 test/documents/gadfly_formats_test.jnw delete mode 100644 test/documents/gadfly_formats_test.txt delete mode 100644 test/documents/gadfly_formats_test_jssvg_ref.md delete mode 100644 test/documents/gadfly_formats_test_mmd_ref.md delete mode 100644 test/documents/gadfly_formats_test_pandoc_ref.md delete mode 100644 test/documents/gadfly_formats_test_ps_ref.tex delete mode 100644 test/documents/gadfly_formats_test_ref.rst delete mode 100644 test/documents/gadfly_formats_test_ref.tex delete mode 100644 test/documents/gadfly_formats_test_svg_ref.md delete mode 100644 test/documents/gadfly_formats_test_tikz_ref.tex delete mode 100644 test/documents/gadfly_markdown_test_ref.md diff --git a/Project.toml b/Project.toml index 52d0b25..835aaec 100644 --- a/Project.toml +++ b/Project.toml @@ -25,6 +25,8 @@ Mustache = ">=0.4.1" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004" +Cairo = "159f3aea-2a34-519c-b102-8c37f9878175" [targets] -test = ["Test", "Plots"] +test = ["Test", "Plots", "Gadfly", "Cairo"] diff --git a/src/Weave.jl b/src/Weave.jl index 5c2933c..2020de0 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -100,15 +100,16 @@ function weave(source ; doctype = :auto, doc = read_doc(source, informat) doctype == :auto && (doctype = detect_doctype(doc.source)) doc.doctype = doctype - template != nothing && (doc.template = template) - highlight_theme != nothing && (doc.highlight_theme = highlight_theme) - css != nothing && (doc.css = css) # Read args from document header, overrides command line args if haskey(doc.header, "options") (doctype, informat, out_path, args, mod, fig_path, fig_ext, cache_path, cache, throw_errors, template, highlight_theme, css, - pandoc_options, latex_cmd) = header_args(doc) + pandoc_options, latex_cmd) = header_args(doc, out_path, mod, + fig_ext, fig_path, + cache_path, cache, throw_errors, + template, highlight_theme, css, + pandoc_options, latex_cmd) end template != nothing && (doc.template = template) diff --git a/src/config.jl b/src/config.jl index 0d0990a..a9f2403 100644 --- a/src/config.jl +++ b/src/config.jl @@ -96,28 +96,31 @@ header_args(doc::WeaveDoc)` Get weave arguments from document header """ -function header_args(doc::WeaveDoc) +function header_args(doc::WeaveDoc, out_path, mod, fig_ext, fig_path, + cache_path, cache, throw_errors,template, + highlight_theme, css, + pandoc_options, latex_cmd) args = getvalue(doc.header, "options", Dict()) doctype = getvalue(args, "doctype", doc.doctype) args = combine_args(args, doctype) informat = getvalue(args, "informat", :auto) - out_path = getvalue(args, "out_path", :doc) + out_path = getvalue(args, "out_path", out_path) out_path == ":pwd" && (out_path = :pwd) isa(out_path, Symbol) || (out_path = joinpath(dirname(doc.source), out_path)) - mod = Symbol(getvalue(args, "mod", :sandbox)) - fig_path = getvalue(args, "fig_path", "figures") - fig_ext = getvalue(args, "fig_ext", nothing) - cache_path = getvalue(args, "cache_path", "cache") - cache = Symbol(getvalue(args, "cache", :off)) - throw_errors = getvalue(args, "throw_errors", false) - template = getvalue(args, "template", nothing) + mod = Symbol(getvalue(args, "mod", mod)) + fig_path = getvalue(args, "fig_path", fig_path) + fig_ext = getvalue(args, "fig_ext", fig_ext) + cache_path = getvalue(args, "cache_path", cache_path) + cache = Symbol(getvalue(args, "cache", cache)) + throw_errors = getvalue(args, "throw_errors", throw_errors) + template = getvalue(args, "template", template) if template != nothing && !isempty(template) template = joinpath(dirname(doc.source), template) end - highlight_theme = getvalue(args, "highlight_theme", nothing) - css = getvalue(args, "css", nothing) - pandoc_options = getvalue(args, "pandoc_options", String[]) - latex_cmd = getvalue(args, "latex_cmd", "xelatex") + highlight_theme = getvalue(args, "highlight_theme", highlight_theme) + css = getvalue(args, "css", css) + pandoc_options = getvalue(args, "pandoc_options", pandoc_options) + latex_cmd = getvalue(args, "latex_cmd", latex_cmd) return (doctype, informat, out_path, args, mod, fig_path, fig_ext, cache_path, cache, throw_errors, template, highlight_theme, css, diff --git a/src/display_methods.jl b/src/display_methods.jl index 81419de..6fb3ea9 100644 --- a/src/display_methods.jl +++ b/src/display_methods.jl @@ -43,7 +43,7 @@ function Base.display(report::Report, data) #Set preferred mimetypes for report based on format fig_ext = report.cur_chunk.options[:fig_ext] for m in unique([mimetype_ext[fig_ext] ; report.mimetypes]) - if showable(m, data) + if Base.invokelatest(showable, m, data) try if !istextmime(m) Compat.invokelatest(display, report, m, data) diff --git a/src/format.jl b/src/format.jl index a577213..ee9b5c5 100644 --- a/src/format.jl +++ b/src/format.jl @@ -24,7 +24,7 @@ function format(doc::WeaveDoc) #strip header if isa(doc.chunks[1], DocChunk) - if occursin("md2", doc.doctype) + if !occursin("pandoc", doc.doctype) doc.chunks[1] = strip_header(doc.chunks[1]) end end diff --git a/src/gadfly.jl b/src/gadfly.jl index d9e8e12..e2a9e75 100644 --- a/src/gadfly.jl +++ b/src/gadfly.jl @@ -10,6 +10,13 @@ end Gadfly.set_default_plot_format(:svg) +Base.showable(m::MIME"application/pdf", p::Gadfly.Plot) = true +Base.showable(m::MIME"application/png", p::Gadfly.Plot) = true + +function Base.display(report::Weave.Report, m::MIME"application/pdf", p::Gadfly.Plot) + display(report, MIME("image/svg+xml"), p) +end + function Base.display(report::Weave.Report, m::MIME"image/png", p::Gadfly.Plot) display(report, MIME("image/svg+xml"), p) end @@ -17,7 +24,6 @@ end #Gadfly doesn't call the default display methods, this catches #all Gadfly plots function Base.display(report::Weave.Report, m::MIME"image/svg+xml", p::Gadfly.Plot) - chunk = report.cur_chunk w = chunk.options[:fig_width]Gadfly.inch @@ -46,4 +52,4 @@ function Base.display(report::Weave.Report, m::MIME"image/svg+xml", p::Gadfly.Pl @warn("Can't save figure. Unsupported format, $format") end end -end \ No newline at end of file +end diff --git a/src/pyplot.jl b/src/pyplot.jl deleted file mode 100644 index 3bb36fd..0000000 --- a/src/pyplot.jl +++ /dev/null @@ -1,20 +0,0 @@ -import PyPlot - -function savefigs_pyplot(report::Report) - chunk = report.cur_chunk - fignames = AbstractString[] - ext = report.formatdict[:fig_ext] - figpath = joinpath(report.cwd, chunk.options[:fig_path]) - isdir(figpath) || mkdir(figpath) - chunkid = (chunk.options[:label] == nothing) ? chunk.number : chunk.options[:label] - #Iterate over all open figures, save them and store names - - for fig = PyPlot.plt[:get_fignums]() - full_name, rel_name = get_figname(report, chunk, fignum=fig) - PyPlot.savefig(full_name, dpi=chunk.options[:dpi]) - push!(report.figures, rel_name) - report.fignum += 1 - PyPlot.plt[:draw]() - PyPlot.plt[:close]() - end -end diff --git a/test/documents/gadfly/gadfly_formats_test.md.pdf.github b/test/documents/gadfly/gadfly_formats_test.md.pdf.github new file mode 100644 index 0000000..1cb2883 --- /dev/null +++ b/test/documents/gadfly/gadfly_formats_test.md.pdf.github @@ -0,0 +1,18 @@ + +````julia +using Gadfly +x = range(0, stop =2π, step=0.05) +plot(x=x, y = sin.(x), Geom.line) +```` + + +![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.pdf) + +![cos(x) function.](figures/gadfly_formats_test_2_1.pdf) + +````julia +plot(x=x, y = cos.(2x), Geom.line) +```` + + +![](figures/gadfly_formats_test_cos2_fun_1.pdf) diff --git a/test/documents/gadfly/gadfly_formats_test.md.png.github b/test/documents/gadfly/gadfly_formats_test.md.png.github new file mode 100644 index 0000000..1fc2c1d --- /dev/null +++ b/test/documents/gadfly/gadfly_formats_test.md.png.github @@ -0,0 +1,18 @@ + +````julia +using Gadfly +x = range(0, stop =2π, step=0.05) +plot(x=x, y = sin.(x), Geom.line) +```` + + +![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.png) + +![cos(x) function.](figures/gadfly_formats_test_2_1.png) + +````julia +plot(x=x, y = cos.(2x), Geom.line) +```` + + +![](figures/gadfly_formats_test_cos2_fun_1.png) diff --git a/test/documents/gadfly/gadfly_formats_test.md.png.pandoc b/test/documents/gadfly/gadfly_formats_test.md.png.pandoc new file mode 100644 index 0000000..d900a53 --- /dev/null +++ b/test/documents/gadfly/gadfly_formats_test.md.png.pandoc @@ -0,0 +1,23 @@ +--- +options : + out_path : gadfly +--- + +~~~~{.julia} +using Gadfly +x = range(0, stop =2π, step=0.05) +plot(x=x, y = sin.(x), Geom.line) +~~~~~~~~~~~~~ + + +![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.png){#fig:sin_fun} + +![cos(x) function.](figures/gadfly_formats_test_2_1.png) + +~~~~{.julia} +plot(x=x, y = cos.(2x), Geom.line) +~~~~~~~~~~~~~ + + +![](figures/gadfly_formats_test_cos2_fun_1.png){width=15cm #fig:cos2_fun}\ + diff --git a/test/documents/gadfly/gadfly_formats_test.md.svg.github b/test/documents/gadfly/gadfly_formats_test.md.svg.github new file mode 100644 index 0000000..021fd36 --- /dev/null +++ b/test/documents/gadfly/gadfly_formats_test.md.svg.github @@ -0,0 +1,18 @@ + +````julia +using Gadfly +x = range(0, stop =2π, step=0.05) +plot(x=x, y = sin.(x), Geom.line) +```` + + +![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.svg) + +![cos(x) function.](figures/gadfly_formats_test_2_1.svg) + +````julia +plot(x=x, y = cos.(2x), Geom.line) +```` + + +![](figures/gadfly_formats_test_cos2_fun_1.svg) diff --git a/test/documents/gadfly/gadfly_formats_test.tex.pdf.tex b/test/documents/gadfly/gadfly_formats_test.tex.pdf.tex new file mode 100644 index 0000000..01fd6d2 --- /dev/null +++ b/test/documents/gadfly/gadfly_formats_test.tex.pdf.tex @@ -0,0 +1,23 @@ + +\begin{juliacode} +using Gadfly +x = range(0, stop =2π, step=0.05) +plot(x=x, y = sin.(x), Geom.line) +\end{juliacode} +\begin{figure}[ht] +\center +\includegraphics[width=\linewidth]{figures/gadfly_formats_test_sin_fun_1.pdf} +\caption{sin(x) function.} +\label{fig:sin_fun} +\end{figure} + +\begin{figure}[htpb] +\center +\includegraphics[width=\linewidth]{figures/gadfly_formats_test_2_1.pdf} +\caption{cos(x) function.} +\end{figure} + +\begin{juliacode} +plot(x=x, y = cos.(2x), Geom.line) +\end{juliacode} +\includegraphics[width=15cm]{figures/gadfly_formats_test_cos2_fun_1.pdf} diff --git a/test/documents/gadfly/gadfly_formats_test.tex.png.tex b/test/documents/gadfly/gadfly_formats_test.tex.png.tex new file mode 100644 index 0000000..435bf3e --- /dev/null +++ b/test/documents/gadfly/gadfly_formats_test.tex.png.tex @@ -0,0 +1,23 @@ + +\begin{juliacode} +using Gadfly +x = range(0, stop =2π, step=0.05) +plot(x=x, y = sin.(x), Geom.line) +\end{juliacode} +\begin{figure}[ht] +\center +\includegraphics[width=\linewidth]{figures/gadfly_formats_test_sin_fun_1.png} +\caption{sin(x) function.} +\label{fig:sin_fun} +\end{figure} + +\begin{figure}[htpb] +\center +\includegraphics[width=\linewidth]{figures/gadfly_formats_test_2_1.png} +\caption{cos(x) function.} +\end{figure} + +\begin{juliacode} +plot(x=x, y = cos.(2x), Geom.line) +\end{juliacode} +\includegraphics[width=15cm]{figures/gadfly_formats_test_cos2_fun_1.png} diff --git a/test/documents/gadfly_formats_test.jnw b/test/documents/gadfly_formats_test.jnw new file mode 100644 index 0000000..d51206b --- /dev/null +++ b/test/documents/gadfly_formats_test.jnw @@ -0,0 +1,19 @@ +--- +options : + out_path : gadfly +--- + +<>= +using Gadfly +x = range(0, stop =2π, step=0.05) +plot(x=x, y = sin.(x), Geom.line) +@ + + +<>= +plot(x=x, y = cos.(x), Geom.line) +@ + +<>= +plot(x=x, y = cos.(2x), Geom.line) +@ diff --git a/test/documents/gadfly_formats_test.txt b/test/documents/gadfly_formats_test.txt deleted file mode 100644 index cbd593c..0000000 --- a/test/documents/gadfly_formats_test.txt +++ /dev/null @@ -1,29 +0,0 @@ - - -<>= -using Gadfly -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -@ - -<>= -plot(x=x, y = cos(x), Geom.line) -@ - -<>= -plot(x=x, y = cos(2x), Geom.line) -@ - -<>= -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -y = 20 -plot(x=x, y = cos(x), Geom.line) -@ - -<>= -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -y = 20 -plot(x=x, y = cos(x), Geom.line) -@ diff --git a/test/documents/gadfly_formats_test_jssvg_ref.md b/test/documents/gadfly_formats_test_jssvg_ref.md deleted file mode 100644 index 87d70cd..0000000 --- a/test/documents/gadfly_formats_test_jssvg_ref.md +++ /dev/null @@ -1,53 +0,0 @@ -````julia -using Gadfly -x = range(0, stop=2π, length=200) -plot(x=x, y = sin(x), Geom.line) -```` - - -![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.js.svg) - -![cos(x) function.](figures/gadfly_formats_test_2_1.js.svg) - -![](figures/gadfly_formats_test_cos2_fun_1.js.svg) - -````julia -julia> x = range(0, stop=2π, length=200) -200-element LinSpace{Float64}: - 0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319 - -julia> plot(x=x, y = sin(x), Geom.line) -Plot(...) - -```` - - -![](figures/gadfly_formats_test_4_1.js.svg) - -````julia -julia> y = 20 -20 - -julia> plot(x=x, y = cos(x), Geom.line) -Plot(...) - -```` - - -![](figures/gadfly_formats_test_4_2.js.svg) - -````julia -x = range(0, stop=2π, length=200) -plot(x=x, y = sin(x), Geom.line) -```` - - -![](figures/gadfly_formats_test_5_1.js.svg) - -````julia -y = 20 -plot(x=x, y = cos(x), Geom.line) -```` - - -![](figures/gadfly_formats_test_5_2.js.svg) diff --git a/test/documents/gadfly_formats_test_mmd_ref.md b/test/documents/gadfly_formats_test_mmd_ref.md deleted file mode 100644 index 169262f..0000000 --- a/test/documents/gadfly_formats_test_mmd_ref.md +++ /dev/null @@ -1,67 +0,0 @@ -````julia -using Gadfly -x = range(0, stop=2π, length=200) -plot(x=x, y = sin(x), Geom.line) -```` - - -![sin(x) function.][figures/gadfly_formats_test_sin_fun_1.png] - -[figures/gadfly_formats_test_sin_fun_1.png]: figures/gadfly_formats_test_sin_fun_1.png - -![cos(x) function.][figures/gadfly_formats_test_2_1.png] - -[figures/gadfly_formats_test_2_1.png]: figures/gadfly_formats_test_2_1.png - -![][figures/gadfly_formats_test_cos2_fun_1.png] - -[figures/gadfly_formats_test_cos2_fun_1.png]: figures/gadfly_formats_test_cos2_fun_1.png - -````julia -julia> x = range(0, stop=2π, length=200) -200-element LinSpace{Float64}: - 0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319 - -julia> plot(x=x, y = sin(x), Geom.line) -Plot(...) - -```` - - -![][figures/gadfly_formats_test_4_1.png] - -[figures/gadfly_formats_test_4_1.png]: figures/gadfly_formats_test_4_1.png - -````julia -julia> y = 20 -20 - -julia> plot(x=x, y = cos(x), Geom.line) -Plot(...) - -```` - - -![][figures/gadfly_formats_test_4_2.png] - -[figures/gadfly_formats_test_4_2.png]: figures/gadfly_formats_test_4_2.png - -````julia -x = range(0, stop=2π, length=200) -plot(x=x, y = sin(x), Geom.line) -```` - - -![][figures/gadfly_formats_test_5_1.png] - -[figures/gadfly_formats_test_5_1.png]: figures/gadfly_formats_test_5_1.png width=15cm - -````julia -y = 20 -plot(x=x, y = cos(x), Geom.line) -```` - - -![][figures/gadfly_formats_test_5_2.png] - -[figures/gadfly_formats_test_5_2.png]: figures/gadfly_formats_test_5_2.png width=15cm diff --git a/test/documents/gadfly_formats_test_pandoc_ref.md b/test/documents/gadfly_formats_test_pandoc_ref.md deleted file mode 100644 index 41789a4..0000000 --- a/test/documents/gadfly_formats_test_pandoc_ref.md +++ /dev/null @@ -1,58 +0,0 @@ -~~~~{.julia} -using Gadfly -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -~~~~~~~~~~~~~ - - -![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.png) - -![cos(x) function.](figures/gadfly_formats_test_2_1.png) - -![](figures/gadfly_formats_test_cos2_fun_1.png)\ - - -~~~~{.julia} -julia> x = linspace(0, 2π, 200) -200-element LinSpace{Float64}: - 0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319 - -julia> plot(x=x, y = sin(x), Geom.line) -Plot(...) - -~~~~~~~~~~~~~ - - -![](figures/gadfly_formats_test_4_1.png)\ - - -~~~~{.julia} -julia> y = 20 -20 - -julia> plot(x=x, y = cos(x), Geom.line) -Plot(...) - -~~~~~~~~~~~~~ - - -![](figures/gadfly_formats_test_4_2.png)\ - - -~~~~{.julia} -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -~~~~~~~~~~~~~ - - -![](figures/gadfly_formats_test_5_1.png){width=15cm}\ - - -~~~~{.julia} -y = 20 -plot(x=x, y = cos(x), Geom.line) -~~~~~~~~~~~~~ - - -![](figures/gadfly_formats_test_5_2.png){width=15cm}\ - diff --git a/test/documents/gadfly_formats_test_ps_ref.tex b/test/documents/gadfly_formats_test_ps_ref.tex deleted file mode 100644 index a452024..0000000 --- a/test/documents/gadfly_formats_test_ps_ref.tex +++ /dev/null @@ -1,52 +0,0 @@ -\begin{juliacode} -using Gadfly -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -\end{juliacode} -\begin{figure}[ht] -\center -\includegraphics[width=\linewidth]{figures/gadfly_formats_test_sin_fun_1.ps} -\caption{sin(x) function.} -\label{fig:sin_fun} -\end{figure} - -\begin{figure}[htpb] -\center -\includegraphics[width=\linewidth]{figures/gadfly_formats_test_2_1.ps} -\caption{cos(x) function.} -\end{figure} - -\includegraphics[width=\linewidth]{figures/gadfly_formats_test_cos2_fun_1.ps} - -\begin{juliaterm} -julia> x = linspace(0, 2π, 200) -200-element LinSpace{Float64}: - 0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319 - -julia> plot(x=x, y = sin(x), Geom.line) -Plot(...) - -\end{juliaterm} -\includegraphics[width=\linewidth]{figures/gadfly_formats_test_4_1.ps} - -\begin{juliaterm} -julia> y = 20 -20 - -julia> plot(x=x, y = cos(x), Geom.line) -Plot(...) - -\end{juliaterm} -\includegraphics[width=\linewidth]{figures/gadfly_formats_test_4_2.ps} - -\begin{juliacode} -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -\end{juliacode} -\includegraphics[width=15cm]{figures/gadfly_formats_test_5_1.ps} - -\begin{juliacode} -y = 20 -plot(x=x, y = cos(x), Geom.line) -\end{juliacode} -\includegraphics[width=15cm]{figures/gadfly_formats_test_5_2.ps} diff --git a/test/documents/gadfly_formats_test_ref.rst b/test/documents/gadfly_formats_test_ref.rst deleted file mode 100644 index 3e735b6..0000000 --- a/test/documents/gadfly_formats_test_ref.rst +++ /dev/null @@ -1,76 +0,0 @@ -.. code-block:: julia - - using Gadfly - x = linspace(0, 2π, 200) - plot(x=x, y = sin(x), Geom.line) - - - -.. figure:: figures/gadfly_formats_test_sin_fun_1.png - :width: 15 cm - - sin(x) function. - - -.. figure:: figures/gadfly_formats_test_2_1.png - :width: 15 cm - - cos(x) function. - - -.. image:: figures/gadfly_formats_test_cos2_fun_1.png - :width: 15 cm - - -.. code-block:: julia - -julia> x = linspace(0, 2π, 200) -200-element LinSpace{Float64}: - 0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319 - -julia> plot(x=x, y = sin(x), Geom.line) -Plot(...) - - - - -.. image:: figures/gadfly_formats_test_4_1.png - :width: 15 cm - - -.. code-block:: julia - -julia> y = 20 -20 - -julia> plot(x=x, y = cos(x), Geom.line) -Plot(...) - - - - -.. image:: figures/gadfly_formats_test_4_2.png - :width: 15 cm - - -.. code-block:: julia - - x = linspace(0, 2π, 200) - plot(x=x, y = sin(x), Geom.line) - - - -.. image:: figures/gadfly_formats_test_5_1.png - :width: 15cm - - -.. code-block:: julia - - y = 20 - plot(x=x, y = cos(x), Geom.line) - - - -.. image:: figures/gadfly_formats_test_5_2.png - :width: 15cm - diff --git a/test/documents/gadfly_formats_test_ref.tex b/test/documents/gadfly_formats_test_ref.tex deleted file mode 100644 index 70d8632..0000000 --- a/test/documents/gadfly_formats_test_ref.tex +++ /dev/null @@ -1,52 +0,0 @@ -\begin{juliacode} -using Gadfly -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -\end{juliacode} -\begin{figure}[ht] -\center -\includegraphics[width=\linewidth]{figures/gadfly_formats_test_sin_fun_1.pdf} -\caption{sin(x) function.} -\label{fig:sin_fun} -\end{figure} - -\begin{figure}[htpb] -\center -\includegraphics[width=\linewidth]{figures/gadfly_formats_test_2_1.pdf} -\caption{cos(x) function.} -\end{figure} - -\includegraphics[width=\linewidth]{figures/gadfly_formats_test_cos2_fun_1.pdf} - -\begin{juliaterm} -julia> x = linspace(0, 2π, 200) -200-element LinSpace{Float64}: - 0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319 - -julia> plot(x=x, y = sin(x), Geom.line) -Plot(...) - -\end{juliaterm} -\includegraphics[width=\linewidth]{figures/gadfly_formats_test_4_1.pdf} - -\begin{juliaterm} -julia> y = 20 -20 - -julia> plot(x=x, y = cos(x), Geom.line) -Plot(...) - -\end{juliaterm} -\includegraphics[width=\linewidth]{figures/gadfly_formats_test_4_2.pdf} - -\begin{juliacode} -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -\end{juliacode} -\includegraphics[width=15cm]{figures/gadfly_formats_test_5_1.pdf} - -\begin{juliacode} -y = 20 -plot(x=x, y = cos(x), Geom.line) -\end{juliacode} -\includegraphics[width=15cm]{figures/gadfly_formats_test_5_2.pdf} diff --git a/test/documents/gadfly_formats_test_svg_ref.md b/test/documents/gadfly_formats_test_svg_ref.md deleted file mode 100644 index da930ac..0000000 --- a/test/documents/gadfly_formats_test_svg_ref.md +++ /dev/null @@ -1,58 +0,0 @@ -~~~~{.julia} -using Gadfly -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -~~~~~~~~~~~~~ - - -![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.svg) - -![cos(x) function.](figures/gadfly_formats_test_2_1.svg) - -![](figures/gadfly_formats_test_cos2_fun_1.svg)\ - - -~~~~{.julia} -julia> x = linspace(0, 2π, 200) -200-element LinSpace{Float64}: - 0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319 - -julia> plot(x=x, y = sin(x), Geom.line) -Plot(...) - -~~~~~~~~~~~~~ - - -![](figures/gadfly_formats_test_4_1.svg)\ - - -~~~~{.julia} -julia> y = 20 -20 - -julia> plot(x=x, y = cos(x), Geom.line) -Plot(...) - -~~~~~~~~~~~~~ - - -![](figures/gadfly_formats_test_4_2.svg)\ - - -~~~~{.julia} -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -~~~~~~~~~~~~~ - - -![](figures/gadfly_formats_test_5_1.svg){width=15cm}\ - - -~~~~{.julia} -y = 20 -plot(x=x, y = cos(x), Geom.line) -~~~~~~~~~~~~~ - - -![](figures/gadfly_formats_test_5_2.svg){width=15cm}\ - diff --git a/test/documents/gadfly_formats_test_tikz_ref.tex b/test/documents/gadfly_formats_test_tikz_ref.tex deleted file mode 100644 index 41cf8f4..0000000 --- a/test/documents/gadfly_formats_test_tikz_ref.tex +++ /dev/null @@ -1,52 +0,0 @@ -\begin{juliacode} -using Gadfly -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -\end{juliacode} -\begin{figure}[ht] -\center -\resizebox{\linewidth}{!}{\input{figures/gadfly_formats_test_sin_fun_1.tex}} -\caption{sin(x) function.} -\label{fig:sin_fun} -\end{figure} - -\begin{figure}[htpb] -\center -\resizebox{\linewidth}{!}{\input{figures/gadfly_formats_test_2_1.tex}} -\caption{cos(x) function.} -\end{figure} - -\resizebox{\linewidth}{!}{\input{figures/gadfly_formats_test_cos2_fun_1.tex}} - -\begin{juliaterm} -julia> x = linspace(0, 2π, 200) -200-element LinSpace{Float64}: - 0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319 - -julia> plot(x=x, y = sin(x), Geom.line) -Plot(...) - -\end{juliaterm} -\resizebox{\linewidth}{!}{\input{figures/gadfly_formats_test_4_1.tex}} - -\begin{juliaterm} -julia> y = 20 -20 - -julia> plot(x=x, y = cos(x), Geom.line) -Plot(...) - -\end{juliaterm} -\resizebox{\linewidth}{!}{\input{figures/gadfly_formats_test_4_2.tex}} - -\begin{juliacode} -x = linspace(0, 2π, 200) -plot(x=x, y = sin(x), Geom.line) -\end{juliacode} -\resizebox{15cm}{!}{\input{figures/gadfly_formats_test_5_1.tex}} - -\begin{juliacode} -y = 20 -plot(x=x, y = cos(x), Geom.line) -\end{juliacode} -\resizebox{15cm}{!}{\input{figures/gadfly_formats_test_5_2.tex}} diff --git a/test/documents/gadfly_markdown_test_ref.md b/test/documents/gadfly_markdown_test_ref.md deleted file mode 100644 index 6fba715..0000000 --- a/test/documents/gadfly_markdown_test_ref.md +++ /dev/null @@ -1,80 +0,0 @@ - -# Gadfly - -````julia -julia> using Gadfly - -julia> x = range(0, stop=2π, length=200) -200-element LinSpace{Float64}: - 0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319 - -julia> plot(x=x, y = sin(x), Geom.line) -Plot(...) - -```` - - -![](figures/gadfly_markdown_test_1_1.png) - -````julia -julia> y = 20 -20 - -julia> plot(x=x, y = cos(x), Geom.line) -Plot(...) - -```` - - -![](figures/gadfly_markdown_test_1_2.png) - -````julia -x = range(0, stop=200, length=50) -println(x) -```` - - -```` -linspace(0.0,200.0,50) -```` - - - -````julia -julia> using Gadfly - -julia> x = range(0, stop=2π, length=200) -200-element LinSpace{Float64}: - 0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319 - -julia> plot(x=x, y = sin(x), Geom.line) -Plot(...) - -```` - - -![](figures/gadfly_markdown_test_3_1.png) - -````julia -julia> y = 20 -20 - -julia> plot(x=x, y = cos(x), Geom.line) -Plot(...) - -```` - - -![](figures/gadfly_markdown_test_3_2.png) - -````julia -x = range(0, stop=200, length=50) -println(x) -```` - - -```` -linspace(0.0,200.0,50) -```` - - diff --git a/test/gadfly_formats.jl b/test/gadfly_formats.jl index 39846c2..ef23079 100644 --- a/test/gadfly_formats.jl +++ b/test/gadfly_formats.jl @@ -2,59 +2,74 @@ using Weave using Test +function test_gadfly(doctype, fig_ext) + out = weave(joinpath(@__DIR__ , "documents/gadfly_formats_test.jnw"), + out_path = joinpath(@__DIR__ , "documents/gadfly/"), + doctype = doctype, fig_ext = fig_ext) + result = read(out, String) + #cp(out, out*fig_ext*"."*doctype, force=true) # Used when adding new tests + ref = read(out*fig_ext*"."*doctype, String) + @test result == ref + rm(out) +end -weave("documents/gadfly_formats_test.txt", doctype = "tex", plotlib="gadfly") -result = read("documents/gadfly_formats_test.tex", String) -ref = read("documents/gadfly_formats_test_ref.tex", String) -@test result == ref +## +test_gadfly("github", ".png") +test_gadfly("github", ".pdf") +test_gadfly("github", ".svg") +test_gadfly("pandoc", ".png") +test_gadfly("tex", ".pdf") +test_gadfly("tex", ".png") -weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".tex", plotlib="gadfly") -result = read("documents/gadfly_formats_test.tex", String) -ref = read("documents/gadfly_formats_test_tikz_ref.tex", String) -@test result == ref -weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".ps", plotlib="gadfly") -result = read("documents/gadfly_formats_test.tex", String) -ref = read("documents/gadfly_formats_test_ps_ref.tex", String) -@test result == ref - -weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly") -result = read("documents/gadfly_formats_test.md", String) -ref = read("documents/gadfly_formats_test_pandoc_ref.md", String) -@test result == ref - -weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly", fig_ext=".svg") -result = read("documents/gadfly_formats_test.md", String) -ref = read("documents/gadfly_formats_test_svg_ref.md", String) -@test result == ref - -weave("documents/gadfly_formats_test.txt", doctype="github", plotlib="gadfly", fig_ext=".js.svg") -result = read("documents/gadfly_formats_test.md", String) -ref = read("documents/gadfly_formats_test_jssvg_ref.md", String) -@test result == ref - -weave("documents/gadfly_formats_test.txt", doctype="rst", plotlib="gadfly") -result = read("documents/gadfly_formats_test.rst", String) -ref = read("documents/gadfly_formats_test_ref.rst", String) -@test result == ref - -weave("documents/gadfly_formats_test.txt", doctype="multimarkdown", plotlib="gadfly") -result = read("documents/gadfly_formats_test.md", String) -ref = read("documents/gadfly_formats_test_mmd_ref.md", String) -@test result == ref - -weave("documents/gadfly_formats_test.txt", doctype="asciidoc", plotlib="gadfly", - out_path="documents/output") -result = read("documents/output/gadfly_formats_test.txt", String) -ref = read("documents/output/gadfly_formats_test_ref.txt", String) -@test result == ref - -weave("documents/gadfly_markdown_test.jmd", doctype="github",plotlib="gadfly", informat="markdown") -result = read("documents/gadfly_markdown_test.md", String) -ref = read("documents/gadfly_markdown_test_ref.md", String) -@test result == ref - -weave("documents/FIR_design.jl", doctype="pandoc", plotlib="gadfly", informat="script") -result = read("documents/FIR_design.md", String) -ref = read("documents/FIR_design_ref.md", String) -@test result == ref +## +# weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".tex", plotlib="gadfly") +# result = read("documents/gadfly_formats_test.tex", String) +# ref = read("documents/gadfly_formats_test_tikz_ref.tex", String) +# @test result == ref +# +# weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".ps", plotlib="gadfly") +# result = read("documents/gadfly_formats_test.tex", String) +# ref = read("documents/gadfly_formats_test_ps_ref.tex", String) +# @test result == ref +# +# weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly") +# result = read("documents/gadfly_formats_test.md", String) +# ref = read("documents/gadfly_formats_test_pandoc_ref.md", String) +# @test result == ref +# +# weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly", fig_ext=".svg") +# result = read("documents/gadfly_formats_test.md", String) +# ref = read("documents/gadfly_formats_test_svg_ref.md", String) +# @test result == ref +# +# weave("documents/gadfly_formats_test.txt", doctype="github", plotlib="gadfly", fig_ext=".js.svg") +# result = read("documents/gadfly_formats_test.md", String) +# ref = read("documents/gadfly_formats_test_jssvg_ref.md", String) +# @test result == ref +# +# weave("documents/gadfly_formats_test.txt", doctype="rst", plotlib="gadfly") +# result = read("documents/gadfly_formats_test.rst", String) +# ref = read("documents/gadfly_formats_test_ref.rst", String) +# @test result == ref +# +# weave("documents/gadfly_formats_test.txt", doctype="multimarkdown", plotlib="gadfly") +# result = read("documents/gadfly_formats_test.md", String) +# ref = read("documents/gadfly_formats_test_mmd_ref.md", String) +# @test result == ref +# +# weave("documents/gadfly_formats_test.txt", doctype="asciidoc", plotlib="gadfly", +# out_path="documents/output") +# result = read("documents/output/gadfly_formats_test.txt", String) +# ref = read("documents/output/gadfly_formats_test_ref.txt", String) +# @test result == ref +# +# weave("documents/gadfly_markdown_test.jmd", doctype="github",plotlib="gadfly", informat="markdown") +# result = read("documents/gadfly_markdown_test.md", String) +# ref = read("documents/gadfly_markdown_test_ref.md", String) +# @test result == ref +# +# weave("documents/FIR_design.jl", doctype="pandoc", plotlib="gadfly", informat="script") +# result = read("documents/FIR_design.md", String) +# ref = read("documents/FIR_design_ref.md", String) +# @test result == ref diff --git a/test/runtests.jl b/test/runtests.jl index 32eaebf..f2a805d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -39,9 +39,14 @@ using Test include("plotsjl_test.jl") end + @testset "Cache" begin + @info("Testing cache") + include("cache_test.jl") + end + @testset "Gadfly" begin @info("Test: Weaving with Gadfly.jl") - include("cache_test.jl") + include("gadfly_formats.jl") end @testset "Header options" begin