From 26a70f4b6c6573568d4acf83cd0cf6b81e7f3734 2012-03-07 21:53:22 From: Thomas Kluyver Date: 2012-03-07 21:53:22 Subject: [PATCH] Add test for installing, loading, unloading an extension. --- diff --git a/IPython/core/tests/daft_extension.py b/IPython/core/tests/daft_extension.py new file mode 100644 index 0000000..37fefe3 --- /dev/null +++ b/IPython/core/tests/daft_extension.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +""" +Useless IPython extension to test installing and loading extensions. +""" +some_vars = {'arq': 185} + +def load_ipython_extension(ip): + # set up simplified quantity input + ip.push(some_vars) + +def unload_ipython_extension(ip): + ip.drop_by_id(some_vars) diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index dd42552..e3a2e38 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -15,6 +15,7 @@ import nose.tools as nt from IPython.testing import decorators as dec from IPython.testing import tools as tt from IPython.utils import py3compat +from IPython.utils.tempdir import TemporaryDirectory #----------------------------------------------------------------------------- # Test functions begin @@ -394,3 +395,20 @@ def test_prun_quotes(): "Test that prun does not clobber string escapes (GH #1302)" _ip.magic("prun -q x = '\t'") nt.assert_equal(_ip.user_ns['x'], '\t') + +def test_extension(): + tmpdir = TemporaryDirectory() + orig_ipython_dir = _ip.ipython_dir + try: + _ip.ipython_dir = tmpdir.name + nt.assert_raises(ImportError, _ip.magic, "load_ext daft_extension") + url = os.path.join(os.path.dirname(__file__), "daft_extension.py") + _ip.magic("install_ext %s" % url) + _ip.user_ns.pop('arq', None) + _ip.magic("load_ext daft_extension") + tt.assert_equal(_ip.user_ns['arq'], 185) + _ip.magic("unload_ext daft_extension") + assert 'arq' not in _ip.user_ns + finally: + _ip.ipython_dir = orig_ipython_dir +