##// END OF EJS Templates
Merge pull request #8196 from quantopian/jinja-vars-from-config...
Merge pull request #8196 from quantopian/jinja-vars-from-config DEV: Allow supplying jinja vars from python config.

File last commit:

r21148:333d256d
r21162:e4bf8e7e merge
Show More
test_nbconvertapp.py
243 lines | 8.9 KiB | text/x-python | PythonLexer
marcmolla
missing files
r13928 # -*- coding: utf-8 -*-
MinRK
test that `-h` and `--help-all` work for various IPython entry points...
r12354 """Test NbConvertApp"""
MinRK
remove PDF post processor
r16418 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Jonathan Frederic
Added tests directory
r11477
Jonathan Frederic
Added test files, and basic tests
r11478 import os
Richard Everson
noteboook with spaces.ipynb test
r11990 import glob
stonebig <stonebig>
Test no incorrect 'data:image/png;base64,b' in html files.
r12391 import sys
Richard Everson
noteboook with spaces.ipynb test
r11990
Jonathan Frederic
Added tests directory
r11477 from .base import TestsBase
MinRK
remove PDF post processor
r16418 from ..postprocessors import PostProcessorBase
Jonathan Frederic
Added tests directory
r11477
Min RK
use traitlets.tests.utils for help output tests...
r21146 from traitlets.tests.utils import check_help_all_output
Jonathan Frederic
Moved PDF logic into Post-Processor class
r11747 from IPython.testing import decorators as dec
Jonathan Frederic
Fixes for Py3.3
r11547
Jonathan Frederic
Added tests directory
r11477 #-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
MinRK
remove PDF post processor
r16418 class DummyPost(PostProcessorBase):
def postprocess(self, filename):
print("Dummy:%s" % filename)
Jonathan Frederic
s/Test_/Test
r11494 class TestNbConvertApp(TestsBase):
Jonathan Frederic
Added tests directory
r11477 """Collection of NbConvertApp tests"""
Jonathan Frederic
Added test files, and basic tests
r11478
def test_notebook_help(self):
MinRK
test that `-h` and `--help-all` work for various IPython entry points...
r12354 """Will help show if no notebooks are specified?"""
Jonathan Frederic
Added test files, and basic tests
r11478 with self.create_temp_cwd():
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 out, err = self.nbconvert('--log-level 0', ignore_return_code=True)
MinRK
test that `-h` and `--help-all` work for various IPython entry points...
r12354 self.assertIn("see '--help-all'", out)
def test_help_output(self):
"""ipython nbconvert --help-all works"""
Min RK
use traitlets.tests.utils for help output tests...
r21146 check_help_all_output('jupyter_nbconvert')
Jonathan Frederic
Added test files, and basic tests
r11478
def test_glob(self):
"""
Do search patterns work for notebook names?
"""
with self.create_temp_cwd(['notebook*.ipynb']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--to python *.ipynb --log-level 0')
Jonathan Frederic
Updated app tests...
r11639 assert os.path.isfile('notebook1.py')
assert os.path.isfile('notebook2.py')
Jonathan Frederic
Added test files, and basic tests
r11478
def test_glob_subdir(self):
"""
Do search patterns work for subdirectory notebook names?
"""
Paul Ivanov
updated tests to use get_output_error_code
r11828 with self.create_temp_cwd():
Jonathan Frederic
Added test files, and basic tests
r11478 self.copy_files_to(['notebook*.ipynb'], 'subdir/')
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--to python --log-level 0 ' +
Jonathan Frederic
Further refinement
r12133 os.path.join('subdir', '*.ipynb'))
Jonathan Frederic
Updated app tests...
r11639 assert os.path.isfile('notebook1.py')
assert os.path.isfile('notebook2.py')
Jonathan Frederic
Added test files, and basic tests
r11478
def test_explicit(self):
"""
Do explicit notebook names work?
"""
with self.create_temp_cwd(['notebook*.ipynb']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to python notebook2')
Jonathan Frederic
Updated app tests...
r11639 assert not os.path.isfile('notebook1.py')
assert os.path.isfile('notebook2.py')
Jonathan Frederic
Added test files, and basic tests
r11478
Paul Ivanov
updated test for spaces in filename
r11991 @dec.onlyif_cmds_exist('pdflatex')
@dec.onlyif_cmds_exist('pandoc')
Richard Everson
noteboook with spaces.ipynb test
r11990 def test_filename_spaces(self):
"""
Paul Ivanov
updated test for spaces in filename
r11991 Generate PDFs with graphics if notebooks have spaces in the name?
Richard Everson
noteboook with spaces.ipynb test
r11990 """
Paul Ivanov
use notebook which has an image in it for the test
r11993 with self.create_temp_cwd(['notebook2.ipynb']):
os.rename('notebook2.ipynb', 'notebook with spaces.ipynb')
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to pdf'
MinRK
remove PDF post processor
r16418 ' "notebook with spaces"'
' --PDFExporter.latex_count=1'
' --PDFExporter.verbose=True'
)
Paul Ivanov
updated test for spaces in filename
r11991 assert os.path.isfile('notebook with spaces.pdf')
Richard Everson
noteboook with spaces.ipynb test
r11990
Jonathan Frederic
Moved PDF logic into Post-Processor class
r11747 def test_post_processor(self):
MinRK
remove PDF post processor
r16418 """Do post processors work?"""
Jonathan Frederic
Moved PDF logic into Post-Processor class
r11747 with self.create_temp_cwd(['notebook1.ipynb']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 out, err = self.nbconvert('--log-level 0 --to python notebook1 '
Min RK
s/IPython.nbconvert/jupyter_nbconvert/...
r20908 '--post jupyter_nbconvert.tests.test_nbconvertapp.DummyPost')
MinRK
remove PDF post processor
r16418 self.assertIn('Dummy:notebook1.py', out)
Jonathan Frederic
Moved PDF logic into Post-Processor class
r11747
MinRK
test that we don't leave any extra CRs in nbconvert
r12527 @dec.onlyif_cmds_exist('pandoc')
def test_spurious_cr(self):
"""Check for extra CR characters"""
with self.create_temp_cwd(['notebook2.ipynb']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to latex notebook2')
MinRK
test that we don't leave any extra CRs in nbconvert
r12527 assert os.path.isfile('notebook2.tex')
with open('notebook2.tex') as f:
tex = f.read()
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to html notebook2')
MinRK
test that we don't leave any extra CRs in nbconvert
r12527 assert os.path.isfile('notebook2.html')
with open('notebook2.html') as f:
html = f.read()
self.assertEqual(tex.count('\r'), tex.count('\r\n'))
self.assertEqual(html.count('\r'), html.count('\r\n'))
Jonathan Frederic
Moved PDF logic into Post-Processor class
r11747
Paul Ivanov
the last set of pandoc-dependent test
r11833 @dec.onlyif_cmds_exist('pandoc')
stonebig <stonebig>
Test no incorrect 'data:image/png;base64,b' in html files.
r12391 def test_png_base64_html_ok(self):
"""Is embedded png data well formed in HTML?"""
with self.create_temp_cwd(['notebook2.ipynb']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to HTML '
Thomas Kluyver
Move html templates into separate folder
r14047 'notebook2.ipynb --template full')
stonebig <stonebig>
Test no incorrect 'data:image/png;base64,b' in html files.
r12391 assert os.path.isfile('notebook2.html')
with open('notebook2.html') as f:
assert "data:image/png;base64,b'" not in f.read()
@dec.onlyif_cmds_exist('pandoc')
Jonathan Frederic
flavor=template
r11745 def test_template(self):
Jonathan Frederic
Fixed tests
r11740 """
Jonathan Frederic
flavor=template
r11745 Do export templates work?
Jonathan Frederic
Fixed tests
r11740 """
Jonathan Frederic
Fixed tests (because of reveal extension change)
r11767 with self.create_temp_cwd(['notebook2.ipynb']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to slides '
Thomas Kluyver
Remove extraneous template argument from test
r14051 'notebook2.ipynb')
Jonathan Frederic
Fixed tests (because of reveal extension change)
r11767 assert os.path.isfile('notebook2.slides.html')
with open('notebook2.slides.html') as f:
Jonathan Frederic
Fixed tests
r11740 assert '/reveal.css' in f.read()
MinRK
test `nbconvert --output` with and without extension
r17310 def test_output_ext(self):
"""test --output=outputfile[.ext]"""
with self.create_temp_cwd(['notebook1.ipynb']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to python '
MinRK
test `nbconvert --output` with and without extension
r17310 'notebook1.ipynb --output nb.py')
assert os.path.exists('nb.py')
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to python '
MinRK
test `nbconvert --output` with and without extension
r17310 'notebook1.ipynb --output nb2')
assert os.path.exists('nb2.py')
Jonathan Frederic
Fixed tests
r11740
Jonathan Frederic
Added test files, and basic tests
r11478 def test_glob_explicit(self):
"""
Can a search pattern be used along with matching explicit notebook names?
"""
with self.create_temp_cwd(['notebook*.ipynb']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to python '
Jonathan Frederic
Further refinement
r12133 '*.ipynb notebook1.ipynb notebook2.ipynb')
Jonathan Frederic
Updated app tests...
r11639 assert os.path.isfile('notebook1.py')
assert os.path.isfile('notebook2.py')
Jonathan Frederic
Added test files, and basic tests
r11478
def test_explicit_glob(self):
"""
Can explicit notebook names be used and then a matching search pattern?
"""
with self.create_temp_cwd(['notebook*.ipynb']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to=python '
Jonathan Frederic
Further refinement
r12133 'notebook1.ipynb notebook2.ipynb *.ipynb')
Jonathan Frederic
Updated app tests...
r11639 assert os.path.isfile('notebook1.py')
assert os.path.isfile('notebook2.py')
Jonathan Frederic
Added test files, and basic tests
r11478
def test_default_config(self):
"""
Does the default config work?
"""
with self.create_temp_cwd(['notebook*.ipynb', 'ipython_nbconvert_config.py']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0')
Jonathan Frederic
Updated app tests...
r11639 assert os.path.isfile('notebook1.py')
assert not os.path.isfile('notebook2.py')
Jonathan Frederic
Added test files, and basic tests
r11478
def test_override_config(self):
"""
Can the default config be overriden?
"""
Paul Ivanov
updated tests to use get_output_error_code
r11828 with self.create_temp_cwd(['notebook*.ipynb',
'ipython_nbconvert_config.py',
Jonathan Frederic
Added test files, and basic tests
r11478 'override.py']):
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --config="override.py"')
Jonathan Frederic
Updated app tests...
r11639 assert not os.path.isfile('notebook1.py')
assert os.path.isfile('notebook2.py')
marcmolla
missing files
r13928
def test_accents_in_filename(self):
"""
Can notebook names include accents?
"""
MinRK
generate unicode filename...
r14961 with self.create_temp_cwd():
self.create_empty_notebook(u'nb1_análisis.ipynb')
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to python nb1_*')
marcmolla
missing files
r13928 assert os.path.isfile(u'nb1_análisis.py')
MinRK
inconsequential cleanup pass on test_nbconvertapp
r15440 @dec.onlyif_cmds_exist('pdflatex', 'pandoc')
def test_filename_accent_pdf(self):
marcmolla
missing files
r13928 """
Generate PDFs if notebooks have an accent in their name?
"""
MinRK
generate unicode filename...
r14961 with self.create_temp_cwd():
self.create_empty_notebook(u'nb1_análisis.ipynb')
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('--log-level 0 --to pdf "nb1_*"'
MinRK
remove PDF post processor
r16418 ' --PDFExporter.latex_count=1'
' --PDFExporter.verbose=True')
marcmolla
solved pdf postprocess issue for nb with accented names
r13937 assert os.path.isfile(u'nb1_análisis.pdf')
jon
Added a cwd test
r16361
def test_cwd_plugin(self):
"""
Verify that an extension in the cwd can be imported.
"""
with self.create_temp_cwd(['hello.py']):
self.create_empty_notebook(u'empty.ipynb')
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('empty --to html --NbConvertApp.writer_class=\'hello.HelloWriter\'')
jon
Added a cwd test
r16361 assert os.path.isfile(u'hello.txt')
Jessica B. Hamrick
Add a test to check that suffixes aren't applied
r20582
def test_output_suffix(self):
"""
Verify that the output suffix is applied
"""
with self.create_temp_cwd():
self.create_empty_notebook('empty.ipynb')
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('empty.ipynb --to notebook')
Jessica B. Hamrick
Add a test to check that suffixes aren't applied
r20582 assert os.path.isfile('empty.nbconvert.ipynb')
Jessica B. Hamrick
Add --inplace flag
r20584 def test_different_build_dir(self):
Jessica B. Hamrick
Add a test to check that suffixes aren't applied
r20582 """
Verify that the output suffix is not applied
"""
with self.create_temp_cwd():
self.create_empty_notebook('empty.ipynb')
os.mkdir('output')
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert(
'empty.ipynb --to notebook '
Jessica B. Hamrick
Add --inplace flag
r20584 '--FilesWriter.build_directory=output')
Jessica B. Hamrick
Add a test to check that suffixes aren't applied
r20582 assert os.path.isfile('output/empty.ipynb')
Jessica B. Hamrick
Add --inplace flag
r20584
def test_inplace(self):
"""
Verify that the notebook is converted in place
"""
with self.create_temp_cwd():
self.create_empty_notebook('empty.ipynb')
Min RK
don't use get_ipython_cmd for running nbconvert tests
r21148 self.nbconvert('empty.ipynb --to notebook --inplace')
Jessica B. Hamrick
Add --inplace flag
r20584 assert os.path.isfile('empty.ipynb')
assert not os.path.isfile('empty.nbconvert.ipynb')