##// END OF EJS Templates
refactor to improve cell switching in edit mode...
refactor to improve cell switching in edit mode This code was repeated in both CodeCell and TextCell, both of which are extensions of Cell, so this just unifies the logic in Cell. TextCell had logic here to check if the cell was rendered or not, but I don't believe it is possible to end up triggering such a code path. (Should that be required, I can always just add back these methods to TextCell, performing the .rendered==True check, and calling the Cell prior to this, code mirror at_top would only return true on if the cursor was at the first character of the top line. Now, pressing up arrow on any character on the top line will take you to the cell above. The same applies for the bottom line. Pressing down arrow would only go to the next cell if the cursor was at a location *after* the last character (something that is only possible to achieve in vim mode if the last line is empty, for example). Now, down arrow on any character of the last line will go to the next cell.

File last commit:

r12950:bdcd3f61
r15754:d60e793e
Show More
test_ultratb.py
149 lines | 4.5 KiB | text/x-python | PythonLexer
Thomas Kluyver
Add test for non-ascii tracebacks.
r8326 # encoding: utf-8
Thomas Kluyver
Add failing test for issue gh-1456
r8099 """Tests for IPython.core.ultratb
"""
Thomas Kluyver
Add test for non-ascii tracebacks.
r8326 import io
Thomas Kluyver
Add failing test for issue gh-1456
r8099 import os.path
import unittest
from IPython.testing import tools as tt
Thomas Kluyver
Refine unicode tests for ultratb
r12167 from IPython.testing.decorators import onlyif_unicode_paths
Thomas Kluyver
Add failing test for issue gh-1456
r8099 from IPython.utils.syspathcontext import prepended_to_syspath
from IPython.utils.tempdir import TemporaryDirectory
ip = get_ipython()
file_1 = """1
2
3
def f():
1/0
"""
file_2 = """def f():
1/0
"""
class ChangedPyFileTest(unittest.TestCase):
def test_changing_py_file(self):
"""Traceback produced if the line where the error occurred is missing?
https://github.com/ipython/ipython/issues/1456
"""
with TemporaryDirectory() as td:
fname = os.path.join(td, "foo.py")
with open(fname, "w") as f:
f.write(file_1)
with prepended_to_syspath(td):
ip.run_cell("import foo")
with tt.AssertPrints("ZeroDivisionError"):
ip.run_cell("foo.f()")
# Make the file shorter, so the line of the error is missing.
with open(fname, "w") as f:
f.write(file_2)
# For some reason, this was failing on the *second* call after
# changing the file, so we call f() twice.
with tt.AssertNotPrints("Internal Python error", channel='stderr'):
with tt.AssertPrints("ZeroDivisionError"):
ip.run_cell("foo.f()")
with tt.AssertPrints("ZeroDivisionError"):
ip.run_cell("foo.f()")
Thomas Kluyver
Add test for non-ascii tracebacks.
r8326
iso_8859_5_file = u'''# coding: iso-8859-5
def fail():
"""дбИЖ"""
1/0 # дбИЖ
'''
class NonAsciiTest(unittest.TestCase):
Thomas Kluyver
Refine unicode tests for ultratb
r12167 @onlyif_unicode_paths
def test_nonascii_path(self):
Thomas Kluyver
Add test for non-ascii tracebacks.
r8326 # Non-ascii directory name as well.
with TemporaryDirectory(suffix=u'é') as td:
Thomas Kluyver
Refine unicode tests for ultratb
r12167 fname = os.path.join(td, u"fooé.py")
with open(fname, "w") as f:
f.write(file_1)
with prepended_to_syspath(td):
ip.run_cell("import foo")
with tt.AssertPrints("ZeroDivisionError"):
ip.run_cell("foo.f()")
def test_iso8859_5(self):
with TemporaryDirectory() as td:
Thomas Kluyver
Add test for non-ascii tracebacks.
r8326 fname = os.path.join(td, 'dfghjkl.py')
with io.open(fname, 'w', encoding='iso-8859-5') as f:
f.write(iso_8859_5_file)
with prepended_to_syspath(td):
ip.run_cell("from dfghjkl import fail")
with tt.AssertPrints("ZeroDivisionError"):
with tt.AssertPrints(u'дбИЖ', suppress=False):
ip.run_cell('fail()')
Thomas Kluyver
Add failing test for IndentationError display
r8416
indentationerror_file = """if True:
zoon()
"""
class IndentationErrorTest(unittest.TestCase):
def test_indentationerror_shows_line(self):
# See issue gh-2398
with tt.AssertPrints("IndentationError"):
with tt.AssertPrints("zoon()", suppress=False):
ip.run_cell(indentationerror_file)
with TemporaryDirectory() as td:
fname = os.path.join(td, "foo.py")
with open(fname, "w") as f:
f.write(indentationerror_file)
with tt.AssertPrints("IndentationError"):
with tt.AssertPrints("zoon()", suppress=False):
ip.magic('run %s' % fname)
Jez Ng
Fix traceback handling of SyntaxErrors without linenos.
r8589
Thomas Kluyver
Add failing test for SyntaxError display
r12543 se_file_1 = """1
2
7/
"""
se_file_2 = """7/
"""
Jez Ng
Fix traceback handling of SyntaxErrors without linenos.
r8589 class SyntaxErrorTest(unittest.TestCase):
def test_syntaxerror_without_lineno(self):
with tt.AssertNotPrints("TypeError"):
with tt.AssertPrints("line unknown"):
ip.run_cell("raise SyntaxError()")
Thomas Kluyver
Add failing test for SyntaxError display
r12543
def test_changing_py_file(self):
with TemporaryDirectory() as td:
fname = os.path.join(td, "foo.py")
with open(fname, 'w') as f:
f.write(se_file_1)
with tt.AssertPrints(["7/", "SyntaxError"]):
ip.magic("run " + fname)
# Modify the file
with open(fname, 'w') as f:
f.write(se_file_2)
# The SyntaxError should point to the correct line
with tt.AssertPrints(["7/", "SyntaxError"]):
ip.magic("run " + fname)
Thomas Kluyver
Add failing test for gh-4361
r12950
def test_non_syntaxerror(self):
# SyntaxTB may be called with an error other than a SyntaxError
# See e.g. gh-4361
try:
raise ValueError('QWERTY')
except ValueError:
with tt.AssertPrints('QWERTY'):
ip.showsyntaxerror()