##// END OF EJS Templates
raise UsageError on magic not found...
Min RK -
Show More
@@ -2076,7 +2076,7 b' class InteractiveShell(SingletonConfigurable):'
2076 2076 etpl = "Line magic function `%%%s` not found%s."
2077 2077 extra = '' if cm is None else (' (But cell magic `%%%%%s` exists, '
2078 2078 'did you mean that instead?)' % magic_name )
2079 error(etpl % (magic_name, extra))
2079 raise UsageError(etpl % (magic_name, extra))
2080 2080 else:
2081 2081 # Note: this is the distance in the stack to the user's frame.
2082 2082 # This will need to be updated if the internal calling logic gets
@@ -2115,7 +2115,7 b' class InteractiveShell(SingletonConfigurable):'
2115 2115 etpl = "Cell magic `%%{0}` not found{1}."
2116 2116 extra = '' if lm is None else (' (But line magic `%{0}` exists, '
2117 2117 'did you mean that instead?)'.format(magic_name))
2118 error(etpl.format(magic_name, extra))
2118 raise UsageError(etpl.format(magic_name, extra))
2119 2119 elif cell == '':
2120 2120 message = '%%{0} is a cell magic, but the cell body is empty.'.format(magic_name)
2121 2121 if self.find_line_magic(magic_name) is not None:
@@ -74,6 +74,35 b' def test_extract_symbols_raises_exception_with_non_python_code():'
74 74 with nt.assert_raises(SyntaxError):
75 75 code.extract_symbols(source, "hello")
76 76
77
78 def test_magic_not_found():
79 # magic not found raises UsageError
80 with nt.assert_raises(UsageError):
81 _ip.magic('doesntexist')
82
83 # ensure result isn't success when a magic isn't found
84 result = _ip.run_cell('%doesntexist')
85 assert isinstance(result.error_in_exec, UsageError)
86
87
88 def test_cell_magic_not_found():
89 # magic not found raises UsageError
90 with nt.assert_raises(UsageError):
91 _ip.run_cell_magic('doesntexist', 'line', 'cell')
92
93 # ensure result isn't success when a magic isn't found
94 result = _ip.run_cell('%%doesntexist')
95 assert isinstance(result.error_in_exec, UsageError)
96
97
98 def test_magic_error_status():
99 def fail(shell):
100 1/0
101 _ip.register_magic_function(fail)
102 result = _ip.run_cell('%fail')
103 assert isinstance(result.error_in_exec, ZeroDivisionError)
104
105
77 106 def test_config():
78 107 """ test that config magic does not raise
79 108 can happen if Configurable init is moved too early into
General Comments 0
You need to be logged in to leave comments. Login now