New tests for Gadfly and figure formatters, small fixes to formats

pull/21/head
Matti Pastell 2014-12-08 23:51:27 +02:00
parent eaa3f34578
commit d97c45c63d
14 changed files with 503 additions and 8 deletions

4
.gitignore vendored
View File

@ -11,6 +11,10 @@ test/documents/figures
test/documents/*.tex
test/documents/*.md
test/documents/*.rst
test/documents/*.html
test/documents/*.pdf
!test/documents/*ref.*
tmp/
.idea

View File

@ -75,6 +75,7 @@ function weave(source ; doctype = "pandoc", plotlib="PyPlot", informat="noweb",
rcParams[:chunk_defaults][:fig] = false
else
l_plotlib = lowercase(plotlib)
rcParams[:chunk_defaults][:fig] = true
if l_plotlib == "winston"
eval(parse("""include(Pkg.dir("Weave","src","winston.jl"))"""))
rcParams[:plotlib] = "Winston"
@ -196,6 +197,7 @@ function run(parsed)
else
chunk[:result] = run_block(chunk[:content])
end
if rcParams[:plotlib] == "PyPlot"
chunk[:fig] && (chunk[:figure] = savefigs(chunk))
else

View File

@ -26,7 +26,6 @@ function format(executed, doctype)
chunk[:fig_env] == nothing && (chunk[:fig_env] = docformat.formatdict[:fig_env])
chunk[:fig_pos] == nothing && (chunk[:fig_pos] = docformat.formatdict[:fig_pos])
#Format code
result = format_codechunk(chunk, formatdict)
#Handle figures

View File

@ -20,7 +20,7 @@ function Base.display(report::Report, m::MIME"image/png", p::Plot)
chunk[:figure] = [rel_name]
if report.term_state == :text
report.cur_result *= "\n" * report.formatdict[:codeend]
report.cur_result *= "\n" * report.formatdict[:codeend] * "\n"
end

View File

@ -1,13 +1,13 @@
\begin{juliacode}
\begin{juliaterm}
julia> y= [2, 5, 12]
3-element Array{Int64,1}:
2
5
12
\end{juliacode}
\end{juliaterm}

View File

@ -0,0 +1,29 @@
<<fig_cap="sin(x) function."; label="sin_fun"; fig_pos="ht">>=
using Gadfly
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
@
<<echo=false; fig_cap="cos(x) function.">>=
plot(x=x, y = cos(x), Geom.line)
@
<<echo=false; label="cos2_fun">>=
plot(x=x, y = cos(2x), Geom.line)
@
<<term=true;fig_width=5>>=
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
y = 20
plot(x=x, y = cos(x), Geom.line)
@
<<out_width="15cm">>=
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
y = 20
plot(x=x, y = cos(x), Geom.line)
@

View File

@ -0,0 +1,80 @@
````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.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 = linspace(0, 2π, 200)
200-element Array{Float64,1}:
0.0
0.0315738
0.0631476
0.0947214
0.126295
0.157869
0.189443
0.221017
0.25259
0.284164
6.03059
6.06217
6.09374
6.12532
6.15689
6.18846
6.22004
6.25161
6.28319
julia> plot(x=x, y = sin(x), Geom.line)
````
![](figures/gadfly_formats_test_4_1.js.svg)
````julia
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
````
![](figures/gadfly_formats_test_4_2.js.svg)
````julia
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
y = 20
plot(x=x, y = cos(x), Geom.line)
````
![](figures/gadfly_formats_test_5_1.js.svg)
![](figures/gadfly_formats_test_5_2.js.svg)

View File

@ -0,0 +1,80 @@
~~~~{.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 Array{Float64,1}:
0.0
0.0315738
0.0631476
0.0947214
0.126295
0.157869
0.189443
0.221017
0.25259
0.284164
6.03059
6.06217
6.09374
6.12532
6.15689
6.18846
6.22004
6.25161
6.28319
julia> plot(x=x, y = sin(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_1.png)
~~~~{.julia}
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_2.png)
~~~~{.julia}
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
y = 20
plot(x=x, y = cos(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_5_1.png)
![](figures/gadfly_formats_test_5_2.png)

View File

@ -0,0 +1,102 @@
.. 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 Array{Float64,1}:
0.0
0.0315738
0.0631476
0.0947214
0.126295
0.157869
0.189443
0.221017
0.25259
0.284164
6.03059
6.06217
6.09374
6.12532
6.15689
6.18846
6.22004
6.25161
6.28319
julia> plot(x=x, y = sin(x), Geom.line)
.. 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)
.. 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)
y = 20
plot(x=x, y = cos(x), Geom.line)
.. image:: figures/gadfly_formats_test_5_1.png
:width: 15cm
.. image:: figures/gadfly_formats_test_5_2.png
:width: 15cm

View File

@ -0,0 +1,86 @@
\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}
\begin{figure}[htpb]
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_cos2_fun_1.pdf}
\label{fig:cos2_fun}
\end{figure}
\begin{juliaterm}
julia> x = linspace(0, 2π, 200)
200-element Array{Float64,1}:
0.0
0.0315738
0.0631476
0.0947214
0.126295
0.157869
0.189443
0.221017
0.25259
0.284164
6.03059
6.06217
6.09374
6.12532
6.15689
6.18846
6.22004
6.25161
6.28319
julia> plot(x=x, y = sin(x), Geom.line)
\end{juliacode}
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_4_1.pdf}
\begin{juliacode}
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
\end{juliacode}
\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)
y = 20
plot(x=x, y = cos(x), Geom.line)
\end{juliacode}
\begin{figure}[htpb]
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_1.pdf}
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_2.pdf}
\end{figure}

View File

@ -0,0 +1,80 @@
~~~~{.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 Array{Float64,1}:
0.0
0.0315738
0.0631476
0.0947214
0.126295
0.157869
0.189443
0.221017
0.25259
0.284164
6.03059
6.06217
6.09374
6.12532
6.15689
6.18846
6.22004
6.25161
6.28319
julia> plot(x=x, y = sin(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_1.svg)
~~~~{.julia}
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_2.svg)
~~~~{.julia}
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
y = 20
plot(x=x, y = cos(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_5_1.svg)
![](figures/gadfly_formats_test_5_2.svg)

View File

@ -32,6 +32,7 @@ julia> plot(x=x, y = sin(x), Geom.line)
````
![](figures/gadfly_markdown_test_1_1.png)
@ -43,6 +44,7 @@ julia> plot(x=x, y = cos(x), Geom.line)
````
![](figures/gadfly_markdown_test_1_2.png)
@ -119,6 +121,7 @@ julia> plot(x=x, y = sin(x), Geom.line)
````
![](figures/gadfly_markdown_test_3_1.png)
@ -130,6 +133,7 @@ julia> plot(x=x, y = cos(x), Geom.line)
````
![](figures/gadfly_markdown_test_3_2.png)

30
test/gadfly_formats.jl Normal file
View File

@ -0,0 +1,30 @@
#Test for Gadfly with different chunk options and figure formats
using Weave
using Base.Test
weave("documents/gadfly_formats_test.txt", doctype="tex", plotlib="gadfly")
result = readall(open("documents/gadfly_formats_test.tex"))
ref = readall(open("documents/gadfly_formats_test_ref.tex"))
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly")
result = readall(open("documents/gadfly_formats_test.md"))
ref = readall(open("documents/gadfly_formats_test_pandoc_ref.md"))
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly", fig_ext=".svg")
result = readall(open("documents/gadfly_formats_test.md"))
ref = readall(open("documents/gadfly_formats_test_svg_ref.md"))
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="github", plotlib="gadfly", fig_ext=".js.svg")
result = readall(open("documents/gadfly_formats_test.md"))
ref = readall(open("documents/gadfly_formats_test_jssvg_ref.md"))
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="rst", plotlib="gadfly")
result = readall(open("documents/gadfly_formats_test.rst"))
ref = readall(open("documents/gadfly_formats_test_ref.rst"))
@test result == ref

View File

@ -7,32 +7,31 @@ using Base.Test
weave("documents/chunk_options.noweb", plotlib=nothing)
result = readall(open("documents/chunk_options.md"))
ref = readall(open("documents/chunk_options_ref.md"))
@test result == ref
weave("documents/chunk_options.noweb", doctype="tex", plotlib=nothing)
result = readall(open("documents/chunk_options.tex"))
ref = readall(open("documents/chunk_options_ref.tex"))
@test result == ref
weave("documents/chunk_options.noweb", doctype="texminted", plotlib=nothing)
result = readall(open("documents/chunk_options.tex"))
ref = readall(open("documents/chunk_options_ref.texminted"))
@test result == ref
weave("documents/chunk_options.noweb", doctype="rst", plotlib=nothing)
result = readall(open("documents/chunk_options.rst"))
ref = readall(open("documents/chunk_options_ref.rst"))
@test result == ref
#Test Gadfly and markdown reader, Gadfly only works with 0.3
if VERSION.minor == 3
weave("documents/gadfly_markdown_test.jmd", doctype="github",plotlib="gadfly", informat="markdown")
result = readall(open("documents/gadfly_markdown_test.md"))
ref = readall(open("documents/gadfly_markdown_test_ref.md"))
@test result == ref
include("gadfly_formats.jl")
end