From c152d328ccaa9bfdff66e3aff059c1f55ebdf5a5 2009-07-29 09:18:31 From: Fernando Perez Date: 2009-07-29 09:18:31 Subject: [PATCH] Fix some tests using magics. For some odd reason, %hist isn't getting loaded into the ipython instance running the tests. But by loading it manually, now the tests do run and pass. Similarly, load %clear manually so it can be tested. --- diff --git a/IPython/testing/plugin/ipdoctest.py b/IPython/testing/plugin/ipdoctest.py index f63b588..3743a08 100644 --- a/IPython/testing/plugin/ipdoctest.py +++ b/IPython/testing/plugin/ipdoctest.py @@ -207,6 +207,15 @@ def start_ipython(): _ip.IP.magic_run_ori = _ip.IP.magic_run _ip.IP.magic_run = im + # XXX - For some very bizarre reason, the loading of %history by default is + # failing. This needs to be fixed later, but for now at least this ensures + # that tests that use %hist run to completion. + from IPython import history + history.init_ipython(_ip) + if not hasattr(_ip.IP,'magic_history'): + raise RuntimeError("Can't load magics, aborting") + + # The start call MUST be made here. I'm not sure yet why it doesn't work if # it is made later, at plugin initialization time, but in all my tests, that's # the case. diff --git a/IPython/tests/test_magic.py b/IPython/tests/test_magic.py index 77bdd89..0c31d70 100644 --- a/IPython/tests/test_magic.py +++ b/IPython/tests/test_magic.py @@ -25,16 +25,23 @@ def test_rehashx(): _ip.magic('rehashx') # Practically ALL ipython development systems will have more than 10 aliases - assert len(_ip.IP.alias_table) > 10 + yield (nt.assert_true, len(_ip.IP.alias_table) > 10) for key, val in _ip.IP.alias_table.items(): # we must strip dots from alias names - assert '.' not in key + nt.assert_true('.' not in key) # rehashx must fill up syscmdlist scoms = _ip.db['syscmdlist'] - assert len(scoms) > 10 + yield (nt.assert_true, len(scoms) > 10) +## def doctest_lsmagic(): +## """ +## In [15]: %lsmagic +## Available magic functions: +## %Exit +## """ + def doctest_hist_f(): """Test %hist -f with temporary filename. @@ -42,7 +49,8 @@ def doctest_hist_f(): In [10]: tfile = tempfile.mktemp('.py','tmp-ipython-') - In [11]: %history -n -f $tfile 3 + In [11]: %hist -n -f $tfile 3 + """ @@ -51,9 +59,12 @@ def doctest_hist_r(): XXX - This test is not recording the output correctly. Not sure why... + In [20]: 'hist' in _ip.IP.lsmagic() + Out[20]: True + In [6]: x=1 - In [7]: hist -n -r 2 + In [7]: %hist -n -r 2 x=1 # random hist -n -r 2 # random """ @@ -94,12 +105,13 @@ def test_shist(): @dec.skipif_not_numpy def test_numpy_clear_array_undec(): + from IPython.Extensions import clearcmd + _ip.ex('import numpy as np') _ip.ex('a = np.empty(2)') - - yield nt.assert_true,'a' in _ip.user_ns + yield (nt.assert_true, 'a' in _ip.user_ns) _ip.magic('clear array') - yield nt.assert_false,'a' in _ip.user_ns + yield (nt.assert_false, 'a' in _ip.user_ns) @dec.skip()