mirror of https://github.com/mpastell/Weave.jl
Merge pull request #363 from JunoLab/avi/fixregression
fix header regression, add test, update testpull/367/head
commit
3a7cb360af
|
@ -6,7 +6,7 @@
|
|||
set_rendering_options!(docformat::WeaveFormat; kwargs...) = return
|
||||
|
||||
function restore_header!(doc)
|
||||
(hasproperty(doc.format, :restore_header) && doc.format.restore_header) || return
|
||||
(hasproperty(doc.format, :preserve_header) && doc.format.preserve_header) || return
|
||||
|
||||
# only strips Weave headers
|
||||
delete!(doc.header, WEAVE_OPTION_NAME)
|
||||
|
|
|
@ -103,13 +103,13 @@ str = """
|
|||
α = 10
|
||||
```
|
||||
"""
|
||||
doc = mock_doc(str; doctype = "md2tex")
|
||||
doc = mock_run(str; doctype = "md2tex")
|
||||
Weave.set_rendering_options!(doc.format)
|
||||
doc = Weave.render_doc(doc)
|
||||
@test occursin(Weave.uc2tex("α"), doc)
|
||||
@test !occursin("α", doc)
|
||||
|
||||
doc = mock_doc(str; doctype = "md2tex")
|
||||
doc = mock_run(str; doctype = "md2tex")
|
||||
Weave.set_rendering_options!(doc.format; keep_unicode = true)
|
||||
doc = Weave.render_doc(doc)
|
||||
@test occursin("α", doc)
|
||||
|
|
|
@ -5,14 +5,26 @@ using Weave: WeaveDoc, run_doc
|
|||
# TODO: add test for header processsing
|
||||
# TODO: add test for `include_weave`
|
||||
|
||||
# constructs `WeaveDoc` from `String` and run it
|
||||
function mock_doc(str; informat = "markdown", run = true, doctype = "md2html", kwargs...)
|
||||
function mock_doc(str, informat = "markdown")
|
||||
f = tempname()
|
||||
write(f, str)
|
||||
doc = WeaveDoc(f, informat)
|
||||
return run ? run_doc(doc; doctype = doctype, kwargs...) : doc
|
||||
return WeaveDoc(f, informat)
|
||||
end
|
||||
mock_run(str, informat = "markdown"; kwargs...) = run_doc(mock_doc(str, informat); kwargs...)
|
||||
|
||||
function test_mock_weave(test_function, str; kwargs...)
|
||||
f = tempname()
|
||||
write(f, str)
|
||||
f = weave(f; kwargs...)
|
||||
try
|
||||
weave_body = read(f, String)
|
||||
test_function(weave_body)
|
||||
catch
|
||||
rethrow()
|
||||
finally
|
||||
rm(f)
|
||||
end
|
||||
end
|
||||
macro jmd_str(s) mock_doc(s) end
|
||||
|
||||
|
||||
@testset "Weave" begin
|
||||
|
|
|
@ -3,23 +3,23 @@
|
|||
@static VERSION ≥ v"1.4" && let
|
||||
|
||||
# no limit
|
||||
doc = jmd"""
|
||||
doc = mock_run("""
|
||||
```julia
|
||||
using DataFrames
|
||||
DataFrame(rand(10,3))
|
||||
```
|
||||
"""
|
||||
"""; doctype = "md2html")
|
||||
@test isdefined(doc.chunks[1], :rich_output)
|
||||
@test count("<tr>", doc.chunks[1].rich_output) == 12 # additonal 2 for name and type row
|
||||
|
||||
# limit
|
||||
n = 100000
|
||||
doc = jmd"""
|
||||
doc = mock_run("""
|
||||
```julia
|
||||
using DataFrames
|
||||
DataFrame(rand(n,3))
|
||||
DataFrame(rand($n,3))
|
||||
```
|
||||
"""
|
||||
"""; doctype = "md2html")
|
||||
@test isdefined(doc.chunks[1], :rich_output)
|
||||
@test count("<tr>", doc.chunks[1].rich_output) < n
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ err_str3_1 = get_err_str("plot(x)")
|
|||
err_str3_2 = get_err_str("f(y")
|
||||
|
||||
|
||||
let doc = mock_doc(str; doctype = "github")
|
||||
let doc = mock_run(str; doctype = "github")
|
||||
get_output(i) = doc.chunks[i].output
|
||||
|
||||
@test occursin(err_str1, get_output(1))
|
||||
|
@ -44,6 +44,6 @@ let doc = mock_doc(str; doctype = "github")
|
|||
@test occursin(err_str3_2, get_output(3))
|
||||
end
|
||||
|
||||
@test_throws ArgumentError mock_doc(str; doctype = "github", throw_errors = true)
|
||||
@test_throws ArgumentError mock_run(str; doctype = "github", throw_errors = true)
|
||||
|
||||
# TODO: test error rendering in `rich_output`
|
||||
|
|
|
@ -45,14 +45,14 @@ end
|
|||
weave_options:
|
||||
---
|
||||
"""
|
||||
@test (mock_doc(str; run = true); true) # no throw
|
||||
@test (mock_run(str); true) # no throw
|
||||
end
|
||||
|
||||
|
||||
@testset "dynamic header specifications" begin
|
||||
|
||||
let
|
||||
d = mock_doc("""
|
||||
d = mock_run("""
|
||||
---
|
||||
title: No. `j 1`
|
||||
---
|
||||
|
@ -65,7 +65,7 @@ let
|
|||
|
||||
# run in target module
|
||||
@eval m n = 1
|
||||
d = mock_doc("""
|
||||
d = mock_run("""
|
||||
---
|
||||
title: No. `j n`
|
||||
---
|
||||
|
@ -74,7 +74,7 @@ let
|
|||
|
||||
# strip quotes by default
|
||||
@eval m s = "1"
|
||||
d = mock_doc("""
|
||||
d = mock_run("""
|
||||
---
|
||||
title: No. `j s`
|
||||
---
|
||||
|
@ -119,3 +119,48 @@ let github_options = copy(weave_options)
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
@testset "end to end test" begin
|
||||
|
||||
# preserve header
|
||||
test_mock_weave("""
|
||||
---
|
||||
key: value
|
||||
---
|
||||
|
||||
find_me
|
||||
"""; informat = "markdown", doctype = "github") do body
|
||||
@test occursin("key: \"value\"", body)
|
||||
@test occursin("find_me", body)
|
||||
end
|
||||
|
||||
# only strips weave specific header
|
||||
test_mock_weave("""
|
||||
---
|
||||
key: value
|
||||
weave_options:
|
||||
doctype: github
|
||||
---
|
||||
|
||||
find_me
|
||||
"""; informat = "markdown", doctype = "github") do body
|
||||
@test occursin("key: \"value\"", body)
|
||||
@test !occursin("weave_options", body)
|
||||
@test occursin("find_me", body)
|
||||
end
|
||||
|
||||
# don't preserve header
|
||||
test_mock_weave("""
|
||||
---
|
||||
weave_options:
|
||||
doctype: md2html
|
||||
---
|
||||
|
||||
find_me
|
||||
"""; informat = "markdown", doctype = "md2html") do body
|
||||
@test !occursin("weave_options", body)
|
||||
@test occursin("find_me", body)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
@testset "evaluation module" begin
|
||||
function mock_output(str, mod = nothing)
|
||||
result_doc = mock_doc(str; mod = mod)
|
||||
result_doc = mock_run(str; mod = mod)
|
||||
return result_doc.chunks[1].output
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue