Permalink
Browse files

Remove object references kept by the test suite in a better way.

  • Loading branch information...
1 parent e2c1847 commit e971e2f51d7c33ce08b1625323fd73850758934f @takluyver committed May 11, 2011
Showing with 11 additions and 19 deletions.
  1. +2 −11 IPython/core/tests/test_magic.py
  2. +9 −8 IPython/testing/globalipapp.py
@@ -408,20 +408,11 @@ def test_xdel(self):
_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])
@@ -133,14 +133,15 @@ def update(self,other):
# 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():

0 comments on commit e971e2f

Please sign in to comment.