##// END OF EJS Templates
Backport PR #4336: use simple replacement rather than string formatting in format_kernel_cmd...
Backport PR #4336: use simple replacement rather than string formatting in format_kernel_cmd closes #4334

File last commit:

r12466:3ff9c5cf
r12909:2a627764
Show More
test_nbconvertapp.py
173 lines | 6.3 KiB | text/x-python | PythonLexer
MinRK
Backport PR #4125: Basic exercise of `ipython [subcommand] -h` and help-all...
r12421 """Test NbConvertApp"""
Jonathan Frederic
Added tests directory
r11477 #-----------------------------------------------------------------------------
MinRK
Backport PR #4125: Basic exercise of `ipython [subcommand] -h` and help-all...
r12421 # Copyright (C) 2013 The IPython Development Team
Jonathan Frederic
Added tests directory
r11477 #
MinRK
Backport PR #4125: Basic exercise of `ipython [subcommand] -h` and help-all...
r12421 # Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
Jonathan Frederic
Added tests directory
r11477 #-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Jonathan Frederic
Added test files, and basic tests
r11478 import os
Richard Everson
noteboook with spaces.ipynb test
r11990 import glob
MinRK
Backport PR #4043: don't 'restore_bytes' in from_JSON...
r12466 import sys
Richard Everson
noteboook with spaces.ipynb test
r11990
Jonathan Frederic
Added tests directory
r11477 from .base import TestsBase
MinRK
Backport PR #4125: Basic exercise of `ipython [subcommand] -h` and help-all...
r12421 import IPython.testing.tools as tt
Jonathan Frederic
Moved PDF logic into Post-Processor class
r11747 from IPython.testing import decorators as dec
MinRK
Backport PR #4043: don't 'restore_bytes' in from_JSON...
r12466 from IPython.external.decorators import knownfailureif
Jonathan Frederic
Fixes for Py3.3
r11547
MinRK
Backport PR #4125: Basic exercise of `ipython [subcommand] -h` and help-all...
r12421
Jonathan Frederic
Fixes for Py3.3
r11547 #-----------------------------------------------------------------------------
# Constants
#-----------------------------------------------------------------------------
Jonathan Frederic
Added tests directory
r11477 #-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
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
Backport PR #4125: Basic exercise of `ipython [subcommand] -h` and help-all...
r12421 """Will help show if no notebooks are specified?"""
Jonathan Frederic
Added test files, and basic tests
r11478 with self.create_temp_cwd():
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 out, err = self.call('nbconvert --log-level 0', ignore_return_code=True)
MinRK
Backport PR #4125: Basic exercise of `ipython [subcommand] -h` and help-all...
r12421 self.assertTrue("see '--help-all'" in out, out)
Jonathan Frederic
Added test files, and basic tests
r11478
MinRK
Backport PR #4125: Basic exercise of `ipython [subcommand] -h` and help-all...
r12421 def test_help_output(self):
"""ipython nbconvert --help-all works"""
tt.help_all_output_test('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']):
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 self.call('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/')
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 self.call('nbconvert --to python --log-level 0 ' +
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']):
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 self.call('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')
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 o,e = self.call('nbconvert --log-level 0 --to latex '
'"notebook with spaces" --post PDF '
'--PDFPostProcessor.verbose=True')
Richard Everson
noteboook with spaces.ipynb test
r11990 assert os.path.isfile('notebook with spaces.tex')
Paul Ivanov
updated test for spaces in filename
r11991 assert os.path.isdir('notebook with spaces_files')
assert os.path.isfile('notebook with spaces.pdf')
Richard Everson
noteboook with spaces.ipynb test
r11990
Jonathan Frederic
Fixed tests, broken because of missing pdflatex
r11752 @dec.onlyif_cmds_exist('pdflatex')
Paul Ivanov
the last set of pandoc-dependent test
r11833 @dec.onlyif_cmds_exist('pandoc')
Jonathan Frederic
Moved PDF logic into Post-Processor class
r11747 def test_post_processor(self):
"""
Do post processors work?
"""
with self.create_temp_cwd(['notebook1.ipynb']):
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 self.call('nbconvert --log-level 0 --to latex notebook1 '
'--post PDF --PDFPostProcessor.verbose=True')
Jonathan Frederic
Moved PDF logic into Post-Processor class
r11747 assert os.path.isfile('notebook1.tex')
assert os.path.isfile('notebook1.pdf')
Paul Ivanov
the last set of pandoc-dependent test
r11833 @dec.onlyif_cmds_exist('pandoc')
MinRK
Backport PR #4043: don't 'restore_bytes' in from_JSON...
r12466 def test_png_base64_html_ok(self):
"""Is embedded png data well formed in HTML?"""
with self.create_temp_cwd(['notebook2.ipynb']):
self.call('nbconvert --log-level 0 --to HTML '
'notebook2.ipynb --template full')
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']):
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 self.call('nbconvert --log-level 0 --to slides '
'notebook2.ipynb --template reveal')
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()
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']):
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 self.call('nbconvert --log-level 0 --to python '
'*.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']):
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 self.call('nbconvert --log-level 0 --to=python '
'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']):
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 self.call('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']):
MinRK
Backport PR #3974: nbconvert: Fix app tests on Window7 w/ Python 3.3...
r12213 self.call('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')