summaryrefslogtreecommitdiff
path: root/tests/dispatch
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2014-01-07 01:11:13 +0100
committerFlorian Apolloner <florian@apolloner.eu>2014-01-09 09:27:54 +0100
commit52cad43bc3d3126fcf7e08582373c12e88895cd3 (patch)
treeb36e676b14afd95b3975c9725cf3b84376b4bf46 /tests/dispatch
parent2dcde523abe6dca42d9b2d46a47c402979974c77 (diff)
downloaddjango-52cad43bc3d3126fcf7e08582373c12e88895cd3.tar.gz
Fixed removal of signal receivers in Python 3.4
Make use of `weakref.finalize` and `weakref.WeakMethod` on python 3.4. Simplified the removal of receivers, the old function looked overly complicated. Many thanks go to Antoine Pitrou for helping me to debug and explain all the failures I ran into while writing that patch.
Diffstat (limited to 'tests/dispatch')
-rw-r--r--tests/dispatch/tests/test_saferef.py76
1 files changed, 0 insertions, 76 deletions
diff --git a/tests/dispatch/tests/test_saferef.py b/tests/dispatch/tests/test_saferef.py
deleted file mode 100644
index 6da756362a..0000000000
--- a/tests/dispatch/tests/test_saferef.py
+++ /dev/null
@@ -1,76 +0,0 @@
-import unittest
-
-from django.dispatch.saferef import safeRef
-from django.utils.six.moves import xrange
-
-
-class Test1(object):
- def x(self):
- pass
-
-
-def test2(obj):
- pass
-
-
-class Test2(object):
- def __call__(self, obj):
- pass
-
-
-class SaferefTests(unittest.TestCase):
- def setUp(self):
- ts = []
- ss = []
- for x in xrange(5000):
- t = Test1()
- ts.append(t)
- s = safeRef(t.x, self._closure)
- ss.append(s)
- ts.append(test2)
- ss.append(safeRef(test2, self._closure))
- for x in xrange(30):
- t = Test2()
- ts.append(t)
- s = safeRef(t, self._closure)
- ss.append(s)
- self.ts = ts
- self.ss = ss
- self.closureCount = 0
-
- def tearDown(self):
- del self.ts
- del self.ss
-
- def testIn(self):
- """Test the "in" operator for safe references (cmp)"""
- for t in self.ts[:50]:
- self.assertTrue(safeRef(t.x) in self.ss)
-
- def testValid(self):
- """Test that the references are valid (return instance methods)"""
- for s in self.ss:
- self.assertTrue(s())
-
- def testShortCircuit(self):
- """Test that creation short-circuits to reuse existing references"""
- sd = {}
- for s in self.ss:
- sd[s] = 1
- for t in self.ts:
- if hasattr(t, 'x'):
- self.assertTrue(safeRef(t.x) in sd)
- else:
- self.assertTrue(safeRef(t) in sd)
-
- def testRepresentation(self):
- """Test that the reference object's representation works
-
- XXX Doesn't currently check the results, just that no error
- is raised
- """
- repr(self.ss[-1])
-
- def _closure(self, ref):
- """Dumb utility mechanism to increment deletion counter"""
- self.closureCount += 1