##// END OF EJS Templates
Also catch SyntaxErrors from InputTransformers in run_cell()...
Also catch SyntaxErrors from InputTransformers in run_cell() The run_cell() method is not used in the IPython terminal, so there are two code paths where the SyntaxError needs to be caught. Also, this commit moves the terminal test to IPython/terminal/test/ instead of IPython/app/test. I've checked that this works in the terminal, the Qt console, and the html notebook.

File last commit:

r13525:b06d9d6e
r13525:b06d9d6e
Show More
test_terminal.py
58 lines | 1.5 KiB | text/x-python | PythonLexer
# coding: utf-8
"""Tests for the IPython terminal"""
import os
import tempfile
import shutil
import nose.tools as nt
from IPython.testing.tools import make_tempfile, ipexec
TEST_SYNTAX_ERROR_CMDS = """
from IPython.core.inputtransformer import InputTransformer
%cpaste
class SyntaxErrorTransformer(InputTransformer):
def push(self, line):
pos = line.find('syntaxerror')
if pos >= 0:
e = SyntaxError('input contains "syntaxerror"')
e.text = line
e.offset = pos + 1
raise e
return line
def reset(self):
pass
--
ip = get_ipython()
transformer = SyntaxErrorTransformer()
ip.input_splitter.python_line_transforms.append(transformer)
ip.input_transformer_manager.python_line_transforms.append(transformer)
# now the actual commands
1234
2345 # syntaxerror <- triggered here
3456
"""
def test_syntax_error():
"""Check that the IPython terminal does not abort if a SyntaxError is raised in an InputTransformer"""
try:
tmp = tempfile.mkdtemp()
filename = os.path.join(tmp, 'test_syntax_error.py')
with open(filename, 'w') as f:
f.write(TEST_SYNTAX_ERROR_CMDS)
out, err = ipexec(filename, pipe=True)
nt.assert_equal(err, '')
nt.assert_in('1234', out)
nt.assert_in(' 2345 # syntaxerror <- triggered here', out)
nt.assert_in(' ^', out)
nt.assert_in('SyntaxError: input contains "syntaxerror"', out)
nt.assert_in('3456', out)
finally:
shutil.rmtree(tmp)