From e2c1847a9bebba2d48269d4f6cc3235abe0e3f10 2011-05-09 13:02:41 From: Thomas Kluyver Date: 2011-05-09 13:02:41 Subject: [PATCH] Remove remaining references held by test suite, so that xdel test passes. --- diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 5ead7eb..22d62c6 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -404,11 +404,26 @@ class TestXdel(tt.TempFileMixin): " self.monitor.append(1)\n" "a = A()\n") self.mktmp(src) + # %run creates some hidden references... _ip.magic("run %s" % self.fname) + # ... as does the displayhook. _ip.run_cell("a") + a = _ip.user_ns["a"] monitor = _ip.user_ns["A"].monitor nt.assert_equal(monitor, []) _ip.magic("xdel a") + + # The testing framework stores extra references - we kill those + # here. See IPython.testing.globalipapp.ipnsdict. + _ip.user_ns.killrefs(a) + del a + + # For some reason the test doesn't pass if this is removed. + # TODO: Work out why, and improve the test. + f = sys._getframe() + print f.f_locals + + # Check that a's __del__ method has been called. nt.assert_equal(monitor, [1]) def doctest_who(): diff --git a/IPython/testing/globalipapp.py b/IPython/testing/globalipapp.py index 162dba9..01e271b 100644 --- a/IPython/testing/globalipapp.py +++ b/IPython/testing/globalipapp.py @@ -132,6 +132,15 @@ class ipnsdict(dict): # correct for that ourselves, to ensure consitency with the 'real' # ipython. self['__builtins__'] = __builtin__ + + def killrefs(self, obj): + """For part of the testing, we need to be able to remove + references to an object, which would otherwise be kept in + _savedict.""" + todel = [n for n, o in self._savedict.iteritems() if o is obj] + for n in todel: + del self._savedict[n] + def get_ipython():