Add tests for converters

pull/66/head v0.2.2
Matti Pastell 2016-12-12 19:54:02 +02:00
parent 76bec5c438
commit a1df55e8e1
8 changed files with 391 additions and 56 deletions

View File

@ -51,6 +51,8 @@ function convert_doc(infile::AbstractString, outfile::AbstractString; format = n
open(outfile, "w") do f
write(f, converted)
end
return nothing
end
"""Convert Weave document to Jupyter notebook format"""

View File

@ -3,64 +3,8 @@ using Base.Test
cleanup = true
#Test chunk options and output formats
weave("documents/chunk_options.noweb", plotlib=nothing)
result = readstring(open("documents/chunk_options.md"))
ref = readstring(open("documents/chunk_options_ref.md"))
@test result == ref
cleanup && rm("documents/chunk_options.md")
weave("documents/chunk_options.noweb", doctype="tex", plotlib=nothing)
result = readstring(open("documents/chunk_options.tex"))
ref = readstring(open("documents/chunk_options_ref.tex"))
@test result == ref
cleanup && rm("documents/chunk_options.tex")
weave("documents/chunk_options.noweb", doctype="texminted", plotlib=nothing)
result = readstring(open("documents/chunk_options.tex"))
ref = readstring(open("documents/chunk_options_ref.texminted"))
@test result == ref
cleanup && rm("documents/chunk_options.tex")
weave("documents/chunk_options.noweb", doctype="rst", plotlib=nothing)
result = readstring(open("documents/chunk_options.rst"))
ref = readstring(open("documents/chunk_options_ref.rst"))
@test result == ref
cleanup && rm("documents/chunk_options.rst")
#Test out_path
weave("documents/chunk_options.noweb", doctype="rst",
out_path="documents/outpath_options.rst" , plotlib=nothing)
result = readstring(open("documents/outpath_options.rst"))
ref = readstring(open("documents/chunk_options_ref.rst"))
@test result == ref
cleanup && rm("documents/outpath_options.rst")
#Test tangle
tangle("documents/chunk_options.noweb")
result = readstring(open("documents/chunk_options.jl"))
ref = readstring(open("documents/chunk_options_ref.jl"))
@test result == ref
cleanup && rm("documents/chunk_options.jl")
tangle("documents/chunk_options.noweb", out_path = "documents/outoptions.jl")
result = readstring(open("documents/outoptions.jl"))
ref = readstring(open("documents/chunk_options_ref.jl"))
@test result == ref
cleanup && rm("documents/outoptions.jl")
#Test functions and sandbox clearing
weave("documents/chunk_func.noweb", plotlib=nothing)
result = readstring(open("documents/chunk_func.md"))
ref = readstring(open("documents/chunk_func_ref.md"))
@test result == ref
cleanup && rm("documents/chunk_func.md")
#Test term=true
weave("documents/test_term.jmd", doctype = "pandoc")
result = readstring(open("documents/test_term.md"))
ref = readstring(open("documents/test_term_ref.md"))
@test result == ref
cleanup && rm("documents/test_term.md")

17
test/convert_test.jl Normal file
View File

@ -0,0 +1,17 @@
using Weave
using Base.Test
function convert_test(outfile)
outfile = joinpath("documents/convert", outfile)
infile = "documents/chunk_options.noweb"
convert_doc(infile, outfile)
result = readstring(open(outfile))
ref = readstring(open(outfile * ".ref"))
rm(outfile)
@test result == ref
end
convert_test("chunk_options.jmd")
convert_test("chunk_options.jl")
convert_test("chunk_options.mdw")
convert_test("chunk_options.ipynb")

View File

@ -0,0 +1,179 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
""
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"y= [2, 5, 12]"
],
"metadata": {},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
""
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"x = [12, 10]\nprintln(y)\nprintln(x)"
],
"metadata": {},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
""
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"println(\"Results without code\")\nprintln(x)"
],
"metadata": {},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
""
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"y = randn(5)\nprintln(\"Don't eval, but show code\")"
],
"metadata": {},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
""
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"y = 1:5\nprintln(y)"
],
"metadata": {},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
""
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"a = \"Don't print me\"\nprintln(a)"
],
"metadata": {},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
""
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"println(\"No markup for results.\")"
],
"metadata": {},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"Test wrapping:"
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"println(collect(0:10:1000))"
],
"metadata": {},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
""
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"println(collect(0:10:1000))"
],
"metadata": {},
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
""
],
"metadata": {}
},
{
"outputs": [],
"cell_type": "code",
"source": [
"println(collect(0:10:1000))"
],
"metadata": {},
"execution_count": null
}
],
"nbformat_minor": 2,
"metadata": {
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.5.0"
},
"kernelspec": {
"name": "julia-0.5",
"display_name": "Julia 0.5.0",
"language": "julia"
}
},
"nbformat": 4
}

View File

@ -0,0 +1,70 @@
#'
#+ term=true
y= [2, 5, 12]
#'
#'
#+
x = [12, 10]
println(y)
println(x)
#'
#'
#'
#+ echo=false
println("Results without code")
println(x)
#'
#'
#'
#+ eval=false; tangle=false
y = randn(5)
println("Don't eval, but show code")
#'
#'
#'
#+
y = 1:5
println(y)
#'
#'
#+ results="hidden"
a = "Don't print me"
println(a)
#'
#'
#+ results="as_is"
println("No markup for results.")
#'
#'
#' Test wrapping:
#'
#+
println(collect(0:10:1000))
#'
#'
#+ wrap=false
println(collect(0:10:1000))
#'
#'
#+ line_width=60
println(collect(0:10:1000))

View File

@ -0,0 +1,60 @@
```julia;term=true
y= [2, 5, 12]
```
```julia
x = [12, 10]
println(y)
println(x)
```
```julia;echo=false
println("Results without code")
println(x)
```
```julia;eval=false; tangle=false
y = randn(5)
println("Don't eval, but show code")
```
```julia
y = 1:5
println(y)
```
```julia;results="hidden"
a = "Don't print me"
println(a)
```
```julia;results="as_is"
println("No markup for results.")
```
Test wrapping:
```julia
println(collect(0:10:1000))
```
```julia;wrap=false
println(collect(0:10:1000))
```
```julia;line_width=60
println(collect(0:10:1000))
```

View File

@ -0,0 +1,60 @@
<<term=true>>=
y= [2, 5, 12]
@
<<>>=
x = [12, 10]
println(y)
println(x)
@
<<echo=false>>=
println("Results without code")
println(x)
@
<<eval=false; tangle=false>>=
y = randn(5)
println("Don't eval, but show code")
@
<<>>=
y = 1:5
println(y)
@
<<results="hidden">>=
a = "Don't print me"
println(a)
@
<<results="as_is">>=
println("No markup for results.")
@
Test wrapping:
<<>>=
println(collect(0:10:1000))
@
<<wrap=false>>=
println(collect(0:10:1000))
@
<<line_width=60>>=
println(collect(0:10:1000))
@

View File

@ -9,6 +9,9 @@ using Base.Test
info("Test: Chunk options")
include("chunk_options.jl")
info("Test: Converting")
include("convert_test.jl")
info("Test: Caching")
include("cache_test.jl")