Skip to content

Commit 5935ff0

Browse files
committed
Add some additional tests that check more proxy behaviors.
1 parent 2a908f6 commit 5935ff0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_weakref.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import unittest
3+
import UserList
34
import weakref
45

56
import test_support
@@ -149,6 +150,23 @@ def test_basic_proxy(self):
149150
o = C()
150151
self.check_proxy(o, weakref.proxy(o))
151152

153+
L = UserList.UserList()
154+
p = weakref.proxy(L)
155+
self.failIf(p, "proxy for empty UserList should be false")
156+
p.append(12)
157+
self.assertEqual(len(L), 1)
158+
self.failUnless(p, "proxy for non-empty UserList should be true")
159+
p[:] = [2, 3]
160+
self.assertEqual(len(L), 2)
161+
self.assertEqual(len(p), 2)
162+
self.failUnless(3 in p, "proxy didn't support __contains__() properly")
163+
p[1] = 5
164+
self.assertEqual(L[1], 5)
165+
self.assertEqual(p[1], 5)
166+
L2 = UserList.UserList(L)
167+
p2 = weakref.proxy(L2)
168+
self.assertEqual(p, p2)
169+
152170
def test_callable_proxy(self):
153171
o = Callable()
154172
ref1 = weakref.proxy(o)

0 commit comments

Comments
 (0)