##// END OF EJS Templates
Backport PR #10737: Raise UsageError on magic not found...
Thomas Kluyver -
Show More
@@ -2064,7 +2064,7 b' class InteractiveShell(SingletonConfigurable):'
2064 2064 etpl = "Line magic function `%%%s` not found%s."
2065 2065 extra = '' if cm is None else (' (But cell magic `%%%%%s` exists, '
2066 2066 'did you mean that instead?)' % magic_name )
2067 error(etpl % (magic_name, extra))
2067 raise UsageError(etpl % (magic_name, extra))
2068 2068 else:
2069 2069 # Note: this is the distance in the stack to the user's frame.
2070 2070 # This will need to be updated if the internal calling logic gets
@@ -2101,7 +2101,7 b' class InteractiveShell(SingletonConfigurable):'
2101 2101 etpl = "Cell magic `%%{0}` not found{1}."
2102 2102 extra = '' if lm is None else (' (But line magic `%{0}` exists, '
2103 2103 'did you mean that instead?)'.format(magic_name))
2104 error(etpl.format(magic_name, extra))
2104 raise UsageError(etpl.format(magic_name, extra))
2105 2105 elif cell == '':
2106 2106 message = '%%{0} is a cell magic, but the cell body is empty.'.format(magic_name)
2107 2107 if self.find_line_magic(magic_name) is not None:
@@ -80,6 +80,35 b' def test_extract_symbols_raises_exception_with_non_python_code():'
80 80 with nt.assert_raises(SyntaxError):
81 81 code.extract_symbols(source, "hello")
82 82
83
84 def test_magic_not_found():
85 # magic not found raises UsageError
86 with nt.assert_raises(UsageError):
87 _ip.magic('doesntexist')
88
89 # ensure result isn't success when a magic isn't found
90 result = _ip.run_cell('%doesntexist')
91 assert isinstance(result.error_in_exec, UsageError)
92
93
94 def test_cell_magic_not_found():
95 # magic not found raises UsageError
96 with nt.assert_raises(UsageError):
97 _ip.run_cell_magic('doesntexist', 'line', 'cell')
98
99 # ensure result isn't success when a magic isn't found
100 result = _ip.run_cell('%%doesntexist')
101 assert isinstance(result.error_in_exec, UsageError)
102
103
104 def test_magic_error_status():
105 def fail(shell):
106 1/0
107 _ip.register_magic_function(fail)
108 result = _ip.run_cell('%fail')
109 assert isinstance(result.error_in_exec, ZeroDivisionError)
110
111
83 112 def test_config():
84 113 """ test that config magic does not raise
85 114 can happen if Configurable init is moved too early into
General Comments 0
You need to be logged in to leave comments. Login now