##// END OF EJS Templates
Fix #4777 and #7887...
Fix #4777 and #7887 The function in charge of actually converting cursor offset to CodeMirror line number and character number was actually crashing when the cursor was at the last character (loop until undefined, then access length of variable, which is undefined). This was hiding a bug in which when you would completer to a single completion pressing tab after as-you-type filtering, the completion would be completed twice. The logic that was supposed to detect whether or not all completions had a common prefix was actually faulty as the common prefix used to be a string but was then changed to an object. Hence the logic to check whether or not there was actually a common prefix was always true, even for empty string, leading to the deletion of the line (replace by '') in some cases.

File last commit:

r19270:0db68b9d
r20538:ae7f6d6a
Show More
test_api.py
49 lines | 1.5 KiB | text/x-python | PythonLexer
"""Test the APIs at the top-level of nbformat"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import json
import os
from .base import TestsBase
from IPython.utils.tempdir import TemporaryDirectory
from ..reader import get_version
from IPython.nbformat import read, current_nbformat, writes, write
class TestAPI(TestsBase):
def test_read(self):
"""Can older notebooks be opened and automatically converted to the current
nbformat?"""
# Open a version 2 notebook.
with self.fopen(u'test2.ipynb', 'r') as f:
nb = read(f, as_version=current_nbformat)
# Check that the notebook was upgraded to the latest version automatically.
(major, minor) = get_version(nb)
self.assertEqual(major, current_nbformat)
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:
nb = read(f, as_version=3)
jsons = writes(nb, version=2)
nb2 = json.loads(jsons)
(major, minor) = get_version(nb2)
self.assertEqual(major, 2)
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)