diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index a87eb75..77f1ca2 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -211,7 +211,7 @@ def test_clear(): nt.assert_true('parrot' in [_ip.user_ns[x] for x in '_i','_ii','_iii']) _ip.magic('%clear in') nt.assert_false('parrot' in [_ip.user_ns[x] for x in '_i','_ii','_iii']) - nt.assert_true(len(_ip.user_ns['In']) == 0) + nt.assert_true(len(set(_ip.user_ns['In'])) == 1) # test '%clear dhist' _ip.run_cell("tmp = [d for d in _dh]") # copy before clearing @@ -222,6 +222,11 @@ def test_clear(): nt.assert_true(len(_ip.user_ns['_dh']) == 0) _ip.run_cell("_dh = [d for d in tmp]") #restore + # test that In length is preserved for %macro + _ip.run_cell("print 'foo'") + _ip.run_cell("clear in") + nt.assert_true(len(_ip.user_ns['In']) == _ip.displayhook.prompt_count+1) + def test_time(): _ip.magic('time None') diff --git a/IPython/extensions/clearcmd.py b/IPython/extensions/clearcmd.py index f9a4074..6787ab7 100644 --- a/IPython/extensions/clearcmd.py +++ b/IPython/extensions/clearcmd.py @@ -45,8 +45,10 @@ def clear_f(self,arg): key = '_i'+repr(n) user_ns.pop(key,None) user_ns.update(dict(_i=u'',_ii=u'',_iii=u'')) - del self.history_manager.input_hist_parsed[:] - del self.history_manager.input_hist_raw[:] + # don't delete these, as %save and %macro depending on the length + # of these lists to be preserved + self.history_manager.input_hist_parsed[:] = [''] * pc + self.history_manager.input_hist_raw[:] = [''] * pc elif target == 'array': # Support cleaning up numpy arrays