From e971e2f51d7c33ce08b1625323fd73850758934f 2011-05-11 13:43:52 From: Thomas Kluyver Date: 2011-05-11 13:43:52 Subject: [PATCH] Remove object references kept by the test suite in a better way. --- diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 22d62c6..f5e3654 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -408,20 +408,11 @@ class TestXdel(tt.TempFileMixin): _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 + _ip.magic("xdel a") # Check that a's __del__ method has been called. nt.assert_equal(monitor, [1]) diff --git a/IPython/testing/globalipapp.py b/IPython/testing/globalipapp.py index 01e271b..cee6f2b 100644 --- a/IPython/testing/globalipapp.py +++ b/IPython/testing/globalipapp.py @@ -133,14 +133,15 @@ class ipnsdict(dict): # 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 __delitem__(self, key): + """Part of the test suite checks that we can release all + references to an object. So we need to make sure that we're not + keeping a reference in _savedict.""" + dict.__delitem__(self, key) + try: + del self._savedict[key] + except KeyError: + pass def get_ipython():