pull/372/head
Shuhei Kadowaki 2020-06-14 01:43:32 +09:00
parent 608bb3df4a
commit 5d3dd15733
19 changed files with 86 additions and 304 deletions

9
.gitignore vendored
View File

@ -1,6 +1,5 @@
Manifest.toml
src/*.cov
test.jl
examples/figures/
examples/*.md
examples/*.pdf
@ -22,15 +21,9 @@ test/**/*.ipynb
doc/build
doc/site
stable/
doc/Manifest.toml
Manifest.toml
tmp/
.idea
*.*~
*.aux
*.log
*.out
\#*\#
.juliahistory

View File

@ -27,12 +27,10 @@ julia = "1.2"
[extras]
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004"
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[targets]
test = ["Cairo", "Conda", "DataFrames", "Gadfly", "IJulia", "Plots", "Test"]
test = ["Cairo", "DataFrames", "Gadfly", "Plots", "Test"]

View File

@ -10,7 +10,7 @@ function plots_set_size!(chunk)
Plots.default(size = (w, h))
end
Weave.push_preexecution_hook!(plots_set_size)
Weave.push_preexecution_hook!(plots_set_size!)
# PNG or SVG is not working, output html
function Base.display(

View File

@ -1,7 +1,4 @@
using Weave
using Test
#Test if running document with and without cache works
# Test if running document with and without cache works
isdir("documents/cache") && rm("documents/cache", recursive = true)
weave("documents/chunk_options.noweb", cache=:all)
result = read("documents/chunk_options.md", String)

View File

@ -1,17 +0,0 @@
Here's some text
And here's some code
```julia
x = 1
y = 2
@show x + y
```
Here's some more complicated code
```julia
@code_native +(1.0, π)
using Test
@test 1 == 1
```

View File

@ -1,31 +0,0 @@
---
title: A minimal beamer example using Weave markdown
author: Matti Pastell
weave_options:
out_path: inline
---
```julia; echo=false
struct Begin
text
title
end
struct End
text
end
Base.show(io::IO, m::MIME"text/latex", b::Begin) = write(io, "\\begin{$(b.text)}[fragile]\n\\frametitle{$(b.title)}\n")
Base.show(io::IO, m::MIME"text/latex", e::End) = write(io, "\\end{$(e.text)}")
Base.show(io::IO, m::MIME"text/html", b::Begin) = write(io, "<div class=\"$(b.title)\">\n")
Base.show(io::IO, m::MIME"text/html", e::End) = write(io, "</div>")
```
! Begin("frame", "Random plot")
Some inline `j print("output")`
```julia
println("Testing output")
```
! End("frame")

View File

@ -1,31 +0,0 @@
```julia
display("text/markdown",
"""
### Small markdown sample
**Hello** from `code` block.
""")
```
```julia
struct Dummy
s::String
end
function Base.show(io::IO, m::MIME"text/markdown", d::Dummy)
print(io, d.s)
end
Dummy("""
* one
* two
* three
""")
```

View File

@ -1,32 +0,0 @@
# NOTE
# this file keeps old end2end tests, which are very fragile
# - they are being gradually replaced with unit tests, that are much more maintainable and
# much more helpful for detecting bugs
# - the purpose of this file is to temporarily keep the old end2end tests in a way that
# they're allowed to fail
tpl = mt"""
{{{ :body }}}
"""
out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2html", template=tpl)
@test read(out, String) == read(out*".ref", String)
rm(out)
out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2tex", template=tpl)
@test read(out, String) == read(out*".ref", String)
rm(out)
@testset "chunk options" begin
result = read("documents/chunk_options.md", String)
ref = read("documents/chunk_options_ref.md", String)
@test result == ref
tangle("documents/chunk_options.noweb", out_path = "documents/tangle")
result = read("documents/tangle/chunk_options.jl", String)
ref = read("documents/tangle/chunk_options.jl.ref", String)
@test ref == result
end

View File

@ -1,85 +1,3 @@
# TODO: this test is horrible, refactor
using Weave: Highlights.Themes.DefaultTheme
# Test rendering of doc chunks
content = """
# Test chunk
Test rendering \$\alpha\$
"""
dchunk = Weave.DocChunk(content, 1, 1)
pformat = Weave.FORMATS["github"]
f = Weave.format_chunk(dchunk, pformat)
@test f == content
docformat = Weave.FORMATS["md2html"]
f_check = "<h1>Test chunk</h1>\n<p>Test rendering <span class=\"math\">\$\alpha\$</span></p>\n"
f = Weave.format_chunk(dchunk, docformat)
@test f_check == f
# Test with actual doc
parsed = Weave.WeaveDoc("documents/chunk_options.noweb")
doc = run_doc(parsed, doctype = "md2html")
c_check = "<pre class='hljl'>\n<span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-p'>[</span><span class='hljl-ni'>12</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-ni'>10</span><span class='hljl-p'>]</span><span class='hljl-t'>\n</span><span class='hljl-nf'>println</span><span class='hljl-p'>(</span><span class='hljl-n'>y</span><span class='hljl-p'>)</span>\n</pre>\n"
doc.format.highlight_theme = DefaultTheme
c = Weave.format_code(doc.chunks[3].content, doc.format)
@test c_check == c
o_check = "\nprintln&#40;x&#41;\n"
o = Weave.format_output(doc.chunks[4].content, doc.format)
@test o_check == o
# Tex format
parsed = Weave.WeaveDoc("documents/chunk_options.noweb")
doc = run_doc(parsed, doctype = "md2tex")
c_check = "\\begin{lstlisting}\n(*@\\HLJLnf{println}@*)(*@\\HLJLp{(}@*)(*@\\HLJLn{x}@*)(*@\\HLJLp{)}@*)\n\\end{lstlisting}\n"
doc.format.highlight_theme = DefaultTheme
c = Weave.format_code(doc.chunks[4].content, doc.format)
@test c_check == c
o_check = "\nx = [12, 10]\nprintln(y)\n"
o = Weave.format_output(doc.chunks[3].content, doc.format)
@test o_check == o
# Test wrapping
cows = repeat("🐄", 100)
testcows = """
🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄
🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄"""
wcows = Weave.wrapline(cows)
@test wcows == testcows
@test length(split(wcows, "\n")[1]) == 75
@test length(split(wcows, "\n")[2]) == 25
tfied = "\\ensuremath{\\bm{\\mathrm{L}}} \\ensuremath{\\bm{\\mathfrak{F}}} \\ensuremath{\\bm{\\iota}} \\ensuremath{\\mathfrak{A}} \\ensuremath{\\bm{\\varTheta}}"
@test Weave.uc2tex("𝐋 𝕱 𝛊 𝔄 𝚹") == tfied
# Test markdown output from chunks
parsed = Weave.WeaveDoc("documents/markdown_output.jmd")
doc = run_doc(parsed, doctype = "md2html")
@test doc.chunks[1].rich_output == "\n<div class=\"markdown\"><h3>Small markdown sample</h3>\n<p><strong>Hello</strong> from <code>code</code> block.</p>\n</div>"
@test doc.chunks[2].rich_output == "\n<div class=\"markdown\"><ul>\n<li><p>one</p>\n</li>\n<li><p>two</p>\n</li>\n<li><p>three</p>\n</li>\n</ul>\n</div>"
ldoc = run_doc(parsed, doctype = "md2tex")
@test ldoc.chunks[1].rich_output == "\n\\subsubsection{Small markdown sample}\n\\textbf{Hello} from \\texttt{code} block.\n\n"
@test ldoc.chunks[2].rich_output == "\n\\begin{itemize}\n\\item one\n\n\n\\item two\n\n\n\\item three\n\n\\end{itemize}\n"
mdoc = run_doc(parsed, doctype = "github")
@test mdoc.chunks[1].rich_output == "\n\n### Small markdown sample\n\n**Hello** from `code` block.\n\n"
@test mdoc.chunks[2].rich_output == "\n\n* one\n* two\n* three\n\n"
# Test disable escaping of unicode
@testset "escape/unescape unicode characters" begin

View File

@ -1,6 +1,9 @@
using Test
import Weave: WeaveMarkdown
import Markdown
# TODO: make this more sensible:
# - separate tests for
# 1. features that are "copy-and-pasted" from `Markdown` module
# 2. features that are extended by Weave
using Weave: WeaveMarkdown, Markdown
# Test markdown2html writer

View File

@ -1,7 +0,0 @@
file = joinpath(@__DIR__, "documents", "jupyter_test.jmd")
using IJulia, Conda
Conda.add("nbconvert") # should be the same as IJulia.JUPYTER, i.e. the miniconda Python
Weave.notebook(file, jupyter_path = IJulia.JUPYTER)
@test "jupyter_test.ipynb" ∈ readdir(@__DIR__) # test if the result was weaved

View File

@ -1,3 +1,5 @@
@testset "evaluation error handling" begin
using Weave: unwrap_load_err
@ -60,4 +62,4 @@ using NonExisting # will be thrown
@test_throws ArgumentError mock_run(str; doctype = "github")
# TODO: test error rendering in `rich_output`
end # @testset "evaluation error handling"

View File

@ -1,3 +1,5 @@
@testset "meta information for evaluation" begin
doc_body = """
```julia
include("test_include.jl")
@ -23,13 +25,13 @@ include("test_include.jl")
read("./test_include.jl", String)
```
"""
doc_dir = joinpath(@__DIR__, "mocks")
doc_path = joinpath(doc_dir, "test_meta.jmd")
doc_dir = normpath(@__DIR__, "..", "mocks")
doc_path = normpath(doc_dir, "test_meta.jmd")
write(doc_path, doc_body)
script_line = ":include_me"
script_body = "$script_line"
script_path = joinpath(@__DIR__, "mocks", "test_include.jl")
script_path = normpath(@__DIR__, "..", "mocks", "test_include.jl")
write(script_path, script_body)
@ -43,3 +45,5 @@ check_output(i, s) = occursin(s, mock.chunks[i].output)
@test check_output(4, doc_path)
@test_broken check_output(5, 18)
@test check_output(6, string('"', script_line, '"')) # current working directory
end # @testset "meta information for evaluation"

49
test/run/test_module.jl Normal file
View File

@ -0,0 +1,49 @@
@testset "module evaluation" begin
function mock_output(str, mod = nothing)
result_doc = mock_run(str; mod = mod)
return result_doc.chunks[1].output
end
str = """
```julia
@__MODULE__
```
"""
# in sandbox
@test occursin(r"\#+WeaveSandBox[\#\d]+", mock_output(str))
# in Main
@test strip(mock_output(str, Main)) == "Main"
end # @testset "module evaluation"
@testset "clear_module!" begin
ary = rand(1000000)
size = Base.summarysize(ary)
# simple case
m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end))
Core.eval(m, :(a = $ary))
Weave.clear_module!(m)
@test Base.summarysize(m) < size
# recursive case
m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end))
Core.eval(m, :(
module $(gensym(:WeaveTestSubModule))
a = $ary
end
))
Weave.clear_module!(m)
@test Base.summarysize(m) < size
# doesn't work with constants
m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end))
Core.eval(m, :(const a = $ary))
Weave.clear_module!(m)
@test_broken Base.summarysize(m) < size
end # @testset "clear_module!"

View File

@ -1,10 +1,14 @@
# TODO:
# - reorganize this
# - test for `include_weave`
# - fire horrible tests
# - test for ipynb integration
# %%
using Weave, Test
using Weave: WeaveDoc, run_doc
# TODO: add test for header processsing
# TODO: add test for `include_weave`
function mock_doc(str, informat = "markdown")
f = tempname()
write(f, str)
@ -27,29 +31,21 @@ function test_mock_weave(test_function, str; kwargs...)
end
# %%
@testset "Weave" begin
@testset "module evaluation" begin
include("test_module_evaluation.jl")
@testset "reader" begin
include("reader/test_chunk_options.jl")
include("reader/test_inline.jl")
end
@testset "header" begin
@testset "header processing" begin
include("test_header.jl")
end
@testset "inline" begin
include("test_inline.jl")
end
@testset "chunk options" begin
include("test_chunk_options.jl")
end
@testset "evaluation's meta info" begin
include("test_meta.jl")
end
@testset "error rendering" begin
include("test_error_rendering.jl")
@testset "run" begin
include("run/test_module.jl")
include("run/test_meta.jl")
include("run/test_error.jl")
end
@testset "conversions" begin
@ -66,15 +62,10 @@ end
include("figureformatter_test.jl")
end
@testset "Cache" begin
@testset "cache" begin
include("cache_test.jl")
end
# @testset "Notebooks" begin
# @info("Testing Jupyter options")
# include("notebooks.jl")
# end
# trigger only on CI
if get(ENV, "CI", nothing) == "true"
@testset "Plots" begin
@ -87,12 +78,4 @@ end
else
@info "skipped Plots.jl and Gadfly.jl integration test"
end
try
@testset "end2end (maybe fail)" begin
include("end2end.jl")
end
catch err
@error err
end
end

View File

@ -1,2 +0,0 @@
{{{ :body }}}

View File

@ -1,45 +0,0 @@
@testset "evaluation module" begin
function mock_output(str, mod = nothing)
result_doc = mock_run(str; mod = mod)
return result_doc.chunks[1].output
end
str = """
```julia
@__MODULE__
```
"""
# in sandbox
@test occursin(r"\#+WeaveSandBox[\#\d]+", mock_output(str))
# in Main
@test strip(mock_output(str, Main)) == "Main"
end
@testset "clear_module!" begin
ary = rand(1000000)
size = Base.summarysize(ary)
# simple case
m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end))
Core.eval(m, :(a = $ary))
Weave.clear_module!(m)
@test Base.summarysize(m) < size
# recursive case
m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end))
Core.eval(m, :(
module $(gensym(:WeaveTestSubModule))
a = $ary
end
))
Weave.clear_module!(m)
@test Base.summarysize(m) < size
# doesn't work with constants
m = Core.eval(@__MODULE__, :(module $(gensym(:WeaveTestModule)) end))
Core.eval(m, :(const a = $ary))
Weave.clear_module!(m)
@test_broken Base.summarysize(m) < size
end