Merge pull request #588 from juhasch/feature/test_preprocessors

Add tests for preprocessors
This commit is contained in:
Josh Barnes
2016-05-03 10:05:01 +01:00
5 changed files with 192 additions and 12 deletions
+56
View File
@@ -0,0 +1,56 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"code_folding": [
0
],
"collapsed": false
},
"outputs": [],
"source": [
"# Codefolding test 1\n",
"'AXYZ12AXY'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"code_folding": [
1
],
"collapsed": true
},
"outputs": [],
"source": [
"# Codefolding test 2\n",
"def myfun():\n",
" 'GR4CX32ZT'"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
@@ -2,27 +2,24 @@
"cells": [
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"a=1"
"a = 'world'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"variables": {
" a ": "world"
}
},
"source": [
"Markdown Cell"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"icon.png\" />"
"Hello {{ a }}"
]
},
{
@@ -51,7 +48,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.1"
"version": "3.5.1"
}
},
"nbformat": 4,
+64
View File
@@ -0,0 +1,64 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"$x=1$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$ x=1$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\\\\( x=1^2 \\\\)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![Tis is a test](tests/data/test.svg)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" y="-7.9185pt" width="58.6929pt" viewBox="-1 -7.9185 58.6929 10.8557" fill="none" version="1.1" stroke-miterlimit="10.000000" stroke-width="0.566929" x="-1pt" height="10.8557pt">
<g transform="matrix(1.000000,0.000000,0.000000,1.000000,0.000000,-0.000000)">
<path fill="black" d="M0.328767 -0M6.1071 -6.0274C6.1071 -6.38605 6.12702 -6.49564 6.89415 -6.49564L7.13325 -6.49564L7.13325 -6.80448C6.78456 -6.7746 6.04732 -6.7746 5.66874 -6.7746C5.29016 -6.7746 4.54296 -6.7746 4.19427 -6.80448L4.19427 -6.49564L4.43337 -6.49564C5.2005 -6.49564 5.22042 -6.38605 5.22042 -6.0274L5.22042 -3.69614L2.24159 -3.69614L2.24159 -6.0274C2.24159 -6.38605 2.26152 -6.49564 3.02864 -6.49564L3.26775 -6.49564L3.26775 -6.80448C2.91905 -6.7746 2.18182 -6.7746 1.80324 -6.7746C1.42466 -6.7746 0.67746 -6.7746 0.328767 -6.80448L0.328767 -6.49564L0.56787 -6.49564C1.33499 -6.49564 1.35492 -6.38605 1.35492 -6.0274L1.35492 -0.777086C1.35492 -0.418431 1.33499 -0.308842 0.56787 -0.308842L0.328767 -0.308842L0.328767 -0C0.67746 -0.0298879 1.41469 -0.0298879 1.79328 -0.0298879C2.17186 -0.0298879 2.91905 -0.0298879 3.26775 -0L3.26775 -0.308842L3.02864 -0.308842C2.26152 -0.308842 2.24159 -0.418431 2.24159 -0.777086L2.24159 -3.3873L5.22042 -3.3873L5.22042 -0.777086C5.22042 -0.418431 5.2005 -0.308842 4.43337 -0.308842L4.19427 -0.308842L4.19427 -0C4.54296 -0.0298879 5.2802 -0.0298879 5.65878 -0.0298879C6.03736 -0.0298879 6.78456 -0.0298879 7.13325 -0L7.13325 -0.308842L6.89415 -0.308842C6.12702 -0.308842 6.1071 -0.418431 6.1071 -0.777086ZM6.1071 -0.777086M7.75093 -0M8.5878 -2.51059C8.64757 -3.99502 9.48443 -4.24408 9.82316 -4.24408C10.8493 -4.24408 10.9489 -2.89913 10.9489 -2.51059ZM10.9489 -2.51059M8.57783 -2.30137L11.3574 -2.30137C11.5766 -2.30137 11.6065 -2.30137 11.6065 -2.51059C11.6065 -3.49689 11.0685 -4.46326 9.82316 -4.46326C8.6675 -4.46326 7.75093 -3.43711 7.75093 -2.19178C7.75093 -0.856787 8.79701 0.109589 9.94271 0.109589C11.1582 0.109589 11.6065 -0.996264 11.6065 -1.18555C11.6065 -1.28518 11.5268 -1.30511 11.477 -1.30511C11.3873 -1.30511 11.3674 -1.24533 11.3474 -1.16563C10.9988 -0.139477 10.1021 -0.139477 10.0025 -0.139477C9.50436 -0.139477 9.10585 -0.438356 8.87671 -0.806974C8.57783 -1.28518 8.57783 -1.94271 8.57783 -2.30137ZM8.57783 -2.30137M12.2242 -0M13.6588 -6.91407L12.2242 -6.80448L12.2242 -6.49564C12.9215 -6.49564 13.0012 -6.4259 13.0012 -5.93773L13.0012 -0.757161C13.0012 -0.308842 12.8917 -0.308842 12.2242 -0.308842L12.2242 -0C12.5529 -0.00996264 13.0809 -0.0298879 13.33 -0.0298879C13.5791 -0.0298879 14.0672 -0.00996264 14.4359 -0L14.4359 -0.308842C13.7684 -0.308842 13.6588 -0.308842 13.6588 -0.757161ZM13.6588 -0.757161M14.9838 -0M16.4184 -6.91407L14.9838 -6.80448L14.9838 -6.49564C15.6812 -6.49564 15.7609 -6.4259 15.7609 -5.93773L15.7609 -0.757161C15.7609 -0.308842 15.6513 -0.308842 14.9838 -0.308842L14.9838 -0C15.3126 -0.00996264 15.8406 -0.0298879 16.0897 -0.0298879C16.3387 -0.0298879 16.8269 -0.00996264 17.1955 -0L17.1955 -0.308842C16.528 -0.308842 16.4184 -0.308842 16.4184 -0.757161ZM16.4184 -0.757161M17.6936 -0M22.1071 -2.132C22.1071 -3.40722 21.1108 -4.46326 19.9054 -4.46326C18.66 -4.46326 17.6936 -3.37733 17.6936 -2.132C17.6936 -0.846824 18.7298 0.109589 19.8954 0.109589C21.1009 0.109589 22.1071 -0.86675 22.1071 -2.132ZM22.1071 -2.132M19.9054 -0.139477C19.477 -0.139477 19.0386 -0.348692 18.7696 -0.806974C18.5205 -1.24533 18.5205 -1.85305 18.5205 -2.21171C18.5205 -2.60025 18.5205 -3.13823 18.7597 -3.57659C19.0286 -4.03487 19.4969 -4.24408 19.8954 -4.24408C20.3337 -4.24408 20.7621 -4.02491 21.0212 -3.59651C21.2802 -3.16812 21.2802 -2.59029 21.2802 -2.21171C21.2802 -1.85305 21.2802 -1.31507 21.061 -0.876712C20.8418 -0.428394 20.4035 -0.139477 19.9054 -0.139477ZM19.9054 -0.139477M23.2528 -0M24.4184 -0.00996264C24.4184 -0.647572 24.1793 -1.05604 23.7808 -1.05604C23.4321 -1.05604 23.2528 -0.787049 23.2528 -0.52802C23.2528 -0.268991 23.4222 -0 23.7808 -0C23.9402 -0 24.0598 -0.0597758 24.1594 -0.139477L24.1793 -0.159402C24.1893 -0.159402 24.1993 -0.14944 24.1993 -0.00996264C24.1993 0.627646 23.9203 1.23537 23.4819 1.70361C23.4222 1.76339 23.4122 1.77335 23.4122 1.8132C23.4122 1.88294 23.462 1.92279 23.5118 1.92279C23.6314 1.92279 24.4184 1.13574 24.4184 -0.00996264ZM24.4184 -0.00996264"/>
<path fill="black" d="M28.6836 -0M34.6711 -3.34745C34.8505 -3.84558 35.1593 -3.97509 35.508 -3.98506L35.508 -4.2939C35.2888 -4.27397 34.9999 -4.26401 34.7807 -4.26401C34.4918 -4.26401 34.0435 -4.28394 33.8542 -4.2939L33.8542 -3.98506C34.2129 -3.97509 34.432 -3.79577 34.432 -3.50685C34.432 -3.44707 34.432 -3.42715 34.3822 -3.29763L33.4756 -0.747198L32.4893 -3.52677C32.4495 -3.64633 32.4395 -3.66625 32.4395 -3.71606C32.4395 -3.98506 32.8281 -3.98506 33.0273 -3.98506L33.0273 -4.2939C32.7384 -4.28394 32.2303 -4.26401 31.9912 -4.26401C31.6923 -4.26401 31.4034 -4.27397 31.1045 -4.2939L31.1045 -3.98506C31.4731 -3.98506 31.6325 -3.96513 31.7322 -3.83562C31.782 -3.77584 31.8916 -3.47696 31.9613 -3.28767L31.1045 -0.876712L30.1581 -3.53674C30.1083 -3.65629 30.1083 -3.67621 30.1083 -3.71606C30.1083 -3.98506 30.4968 -3.98506 30.6961 -3.98506L30.6961 -4.2939C30.3972 -4.28394 29.8393 -4.26401 29.6101 -4.26401C29.5703 -4.26401 29.0423 -4.27397 28.6836 -4.2939L28.6836 -3.98506C29.1817 -3.98506 29.3013 -3.95517 29.4208 -3.63636L30.6761 -0.109589C30.7259 0.0298879 30.7558 0.109589 30.8853 0.109589C31.0149 0.109589 31.0348 0.0498132 31.0846 -0.0896638L32.0908 -2.90909L33.107 -0.0797011C33.1469 0.0298879 33.1767 0.109589 33.3063 0.109589C33.4358 0.109589 33.4657 0.0199253 33.5055 -0.0797011ZM33.5055 -0.0797011"/>
<path fill="black" d="M35.7017 -0M40.1152 -2.132C40.1152 -3.40722 39.1189 -4.46326 37.9134 -4.46326C36.6681 -4.46326 35.7017 -3.37733 35.7017 -2.132C35.7017 -0.846824 36.7378 0.109589 37.9035 0.109589C39.1089 0.109589 40.1152 -0.86675 40.1152 -2.132ZM40.1152 -2.132M37.9134 -0.139477C37.485 -0.139477 37.0467 -0.348692 36.7777 -0.806974C36.5286 -1.24533 36.5286 -1.85305 36.5286 -2.21171C36.5286 -2.60025 36.5286 -3.13823 36.7677 -3.57659C37.0367 -4.03487 37.505 -4.24408 37.9035 -4.24408C38.3418 -4.24408 38.7702 -4.02491 39.0292 -3.59651C39.2883 -3.16812 39.2883 -2.59029 39.2883 -2.21171C39.2883 -1.85305 39.2883 -1.31507 39.0691 -0.876712C38.8499 -0.428394 38.4116 -0.139477 37.9134 -0.139477ZM37.9134 -0.139477M40.683 -0M42.0678 -3.3076L42.0678 -4.40349L40.683 -4.2939L40.683 -3.98506C41.3804 -3.98506 41.4601 -3.91532 41.4601 -3.42715L41.4601 -0.757161C41.4601 -0.308842 41.3505 -0.308842 40.683 -0.308842L40.683 -0C41.0716 -0.00996264 41.5398 -0.0298879 41.8188 -0.0298879C42.2173 -0.0298879 42.6855 -0.0298879 43.084 -0L43.084 -0.308842L42.8748 -0.308842C42.1376 -0.308842 42.1177 -0.418431 42.1177 -0.777086L42.1177 -2.31133C42.1177 -3.29763 42.5361 -4.18431 43.2933 -4.18431C43.363 -4.18431 43.3829 -4.18431 43.4028 -4.17435C43.373 -4.16438 43.1737 -4.04483 43.1737 -3.7858C43.1737 -3.50685 43.3829 -3.35741 43.6021 -3.35741C43.7814 -3.35741 44.0305 -3.47696 44.0305 -3.79577C44.0305 -4.11457 43.7216 -4.40349 43.2933 -4.40349C42.566 -4.40349 42.2073 -3.73599 42.0678 -3.3076ZM42.0678 -3.3076M44.6282 -0M46.0629 -6.91407L44.6282 -6.80448L44.6282 -6.49564C45.3256 -6.49564 45.4053 -6.4259 45.4053 -5.93773L45.4053 -0.757161C45.4053 -0.308842 45.2957 -0.308842 44.6282 -0.308842L44.6282 -0C44.957 -0.00996264 45.485 -0.0298879 45.7341 -0.0298879C45.9832 -0.0298879 46.4713 -0.00996264 46.84 -0L46.84 -0.308842C46.1725 -0.308842 46.0629 -0.308842 46.0629 -0.757161ZM46.0629 -0.757161M47.3979 -0M50.8449 -0.547945L50.8449 0.109589L52.3094 -0L52.3094 -0.308842C51.6121 -0.308842 51.5324 -0.37858 51.5324 -0.86675L51.5324 -6.91407L50.0977 -6.80448L50.0977 -6.49564C50.7951 -6.49564 50.8748 -6.4259 50.8748 -5.93773L50.8748 -3.7858C50.5859 -4.14446 50.1575 -4.40349 49.6195 -4.40349C48.4439 -4.40349 47.3979 -3.42715 47.3979 -2.14197C47.3979 -0.876712 48.3742 0.109589 49.5099 0.109589C50.1475 0.109589 50.5959 -0.229141 50.8449 -0.547945ZM50.8449 -0.547945M50.8449 -3.21793L50.8449 -1.17559C50.8449 -0.996264 50.8449 -0.976339 50.7353 -0.806974C50.4365 -0.328767 49.9881 -0.109589 49.5598 -0.109589C49.1114 -0.109589 48.7528 -0.368618 48.5137 -0.747198C48.2546 -1.15567 48.2248 -1.72354 48.2248 -2.132C48.2248 -2.50062 48.2447 -3.09838 48.5336 -3.5467C48.7428 -3.85554 49.1214 -4.18431 49.6594 -4.18431C50.0081 -4.18431 50.4265 -4.03487 50.7353 -3.58655C50.8449 -3.41719 50.8449 -3.39726 50.8449 -3.21793ZM50.8449 -3.21793M53.4452 -0M54.1127 -2.08219L54.5012 -6.62516C54.5012 -6.95392 54.2322 -7.13325 53.9732 -7.13325C53.7142 -7.13325 53.4452 -6.95392 53.4452 -6.62516L53.8337 -2.09215C53.8437 -1.94271 53.8537 -1.86301 53.9732 -1.86301C54.0728 -1.86301 54.1027 -1.91283 54.1127 -2.08219ZM54.1127 -2.08219M54.5012 -0.52802C54.5012 -0.816936 54.2621 -1.05604 53.9732 -1.05604C53.6843 -1.05604 53.4452 -0.816936 53.4452 -0.52802C53.4452 -0.239103 53.6843 -0 53.9732 -0C54.2621 -0 54.5012 -0.239103 54.5012 -0.52802ZM54.5012 -0.52802"/>
</g>
<path d="M0 -0L56.6929 -0" stroke="black"/>
</svg>

After

Width:  |  Height:  |  Size: 8.8 KiB

+54
View File
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
from nbconvert import RSTExporter, LatexExporter
import nbformat
from traitlets.config import Config
import os
import sys
sys.path.append('extensions')
c = Config()
def test_pymarkdown_preprocessor():
""" Test python markdown preprocessor """
nb_name='tests/data/pymarkdown.ipynb'
with open(nb_name, 'r') as f:
notebook_json = f.read()
notebook = nbformat.reads(notebook_json, as_version=4)
c.RSTExporter.preprocessors = ["pre_pymarkdown.PyMarkdownPreprocessor"]
c.NbConvertApp.export_format = 'rst'
rst_exporter = RSTExporter(config=c)
body = rst_exporter.from_notebook_node(notebook)
with open('test.txt', 'wb') as f:
f.write(body[0].encode('utf8'))
assert 'Hello world' in body[0]
pass
def test_codefolding():
""" Test codefolding preprocessor """
nb_name='tests/data/codefolding.ipynb'
with open(nb_name, 'r') as f:
notebook_json = f.read()
notebook = nbformat.reads(notebook_json, as_version=4)
c.RSTExporter.preprocessors = ["pre_codefolding.CodeFoldingPreprocessor"]
c.NbConvertApp.export_format = 'rst'
rst_exporter = RSTExporter(config=c)
body = rst_exporter.from_notebook_node(notebook)
assert 'AXYZ12AXY' not in body[0] # firstline fold
assert 'GR4CX32ZT' not in body[0] # function fold
def test_svg2pdf_preprocessor():
""" Test svg2pdf preprocessor for markdown cell images """
nb_name='tests/data/svg2pdf.ipynb'
pdf_file='tests/data/test.pdf'
with open(nb_name, 'r') as f:
notebook_json = f.read()
notebook = nbformat.reads(notebook_json, as_version=4)
c.LatexExporter.preprocessors = ["pre_svg2pdf.SVG2PDFPreprocessor"]
c.NbConvertApp.export_format = 'latex'
latex_exporter = LatexExporter(config=c)
body = latex_exporter.from_notebook_node(notebook)
assert os.path.isfile(pdf_file)
os.remove(pdf_file)
assert 'test.pdf' in body[0]