##// END OF EJS Templates
load kwarg traits before loading config...
load kwarg traits before loading config in `Configurable.__init__` avoids problems in the new init of traitlets that skips `_trait_default` if specified in kwargs, which means really nothing should be done before `HasTraits.__init__` has been called. This does mean that such values are assigned twice. Typically, this will have no effect, except when a value is set by both config and kwarg.

File last commit:

r19270:0db68b9d
r20804:8d5ab280
Show More
test_api.py
49 lines | 1.5 KiB | text/x-python | PythonLexer
MinRK
Add top-level IPython.nbformat API...
r18603 """Test the APIs at the top-level of nbformat"""
Jonathan Frederic
Added nbformat ver conv tests, fixed some bugs
r12781
MinRK
add `nbformat.writes(version=X)` for downgrade...
r18246 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import json
Thomas Kluyver
Make nbformat.(read|write) accept file-like object or path
r19270 import os
Jonathan Frederic
Added nbformat ver conv tests, fixed some bugs
r12781
from .base import TestsBase
Thomas Kluyver
Make nbformat.(read|write) accept file-like object or path
r19270 from IPython.utils.tempdir import TemporaryDirectory
Jonathan Frederic
Added nbformat ver conv tests, fixed some bugs
r12781 from ..reader import get_version
Thomas Kluyver
Make nbformat.(read|write) accept file-like object or path
r19270 from IPython.nbformat import read, current_nbformat, writes, write
Jonathan Frederic
Added nbformat ver conv tests, fixed some bugs
r12781
MinRK
Add top-level IPython.nbformat API...
r18603 class TestAPI(TestsBase):
Jonathan Frederic
Added nbformat ver conv tests, fixed some bugs
r12781
def test_read(self):
"""Can older notebooks be opened and automatically converted to the current
nbformat?"""
# Open a version 2 notebook.
MinRK
Add top-level IPython.nbformat API...
r18603 with self.fopen(u'test2.ipynb', 'r') as f:
nb = read(f, as_version=current_nbformat)
Jonathan Frederic
Added nbformat ver conv tests, fixed some bugs
r12781
# Check that the notebook was upgraded to the latest version automatically.
(major, minor) = get_version(nb)
self.assertEqual(major, current_nbformat)
MinRK
add `nbformat.writes(version=X)` for downgrade...
r18246
def test_write_downgrade_2(self):
"""dowgrade a v3 notebook to v2"""
# Open a version 3 notebook.
with self.fopen(u'test3.ipynb', 'r') as f:
MinRK
Add top-level IPython.nbformat API...
r18603 nb = read(f, as_version=3)
MinRK
add `nbformat.writes(version=X)` for downgrade...
r18246
jsons = writes(nb, version=2)
nb2 = json.loads(jsons)
(major, minor) = get_version(nb2)
self.assertEqual(major, 2)
Thomas Kluyver
Make nbformat.(read|write) accept file-like object or path
r19270
def test_read_write_path(self):
"""read() and write() take filesystem paths"""
path = os.path.join(self._get_files_path(), u'test4.ipynb')
nb = read(path, as_version=4)
with TemporaryDirectory() as td:
dest = os.path.join(td, 'echidna.ipynb')
write(nb, dest)
assert os.path.isfile(dest)