Skip to content

Commit

Permalink
Remove remaining references held by test suite, so that xdel test pas…
Browse files Browse the repository at this point in the history
…ses.
  • Loading branch information
takluyver committed May 9, 2011
1 parent ebc0014 commit e2c1847
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions IPython/core/tests/test_magic.py
Expand Up @@ -404,11 +404,26 @@ def test_xdel(self):
" 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():
Expand Down
9 changes: 9 additions & 0 deletions IPython/testing/globalipapp.py
Expand Up @@ -132,6 +132,15 @@ def update(self,other):
# 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():
Expand Down

0 comments on commit e2c1847

Please sign in to comment.