[Python-checkins] CVS: python/dist/src/Lib/test test_iter.py,1.22,1.23
Guido van Rossum
gvanrossum@users.sourceforge.net
2001年12月03日 11:33:27 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv16852/Lib/test
Modified Files:
test_iter.py
Log Message:
unpack_iterable(): Add a missing DECREF in an error case. Reported by
Armin Rigo (SF bug #488477). Added a testcase to test_unpack_iter()
in test_iter.py.
Index: test_iter.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_iter.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** test_iter.py 2001年10月04日 05:36:56 1.22
--- test_iter.py 2001年12月03日 19:33:25 1.23
***************
*** 748,751 ****
--- 748,774 ----
self.assertEqual((a, b, c), (0, 1, 42))
+ # Test reference count behavior
+
+ class C(object):
+ count = 0
+ def __new__(cls):
+ cls.count += 1
+ return object.__new__(cls)
+ def __del__(self):
+ cls = self.__class__
+ assert cls.count > 0
+ cls.count -= 1
+ x = C()
+ self.assertEqual(C.count, 1)
+ del x
+ self.assertEqual(C.count, 0)
+ l = [C(), C(), C()]
+ self.assertEqual(C.count, 3)
+ try:
+ a, b = iter(l)
+ except ValueError:
+ pass
+ del l
+ self.assertEqual(C.count, 0)
def test_main():