[Python-checkins] python/dist/src/Lib/test test_array.py,1.29,1.30

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sun Aug 29 09:50:45 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv772/Lib/test
Modified Files:
	test_array.py 
Log Message:
SF feature request #992967: array.array objects should support sequences.
Made the constructor accept general iterables.
Index: test_array.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_array.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- test_array.py	31 May 2004 00:35:52 -0000	1.29
+++ test_array.py	29 Aug 2004 07:50:43 -0000	1.30
@@ -600,6 +600,26 @@
 array.array(self.typecode, self.example+self.example[::-1])
 )
 
+ def test_constructor_with_iterable_argument(self):
+ a = array.array(self.typecode, iter(self.example))
+ b = array.array(self.typecode, self.example)
+ self.assertEqual(a, b)
+
+ # non-iterable argument
+ self.assertRaises(TypeError, array.array, self.typecode, 10)
+
+ # pass through errors raised in __iter__
+ class A:
+ def __iter__(self):
+ raise UnicodeError
+ self.assertRaises(UnicodeError, array.array, self.typecode, A())
+
+ # pass through errors raised in next()
+ def B():
+ raise UnicodeError
+ yield None
+ self.assertRaises(UnicodeError, array.array, self.typecode, B())
+
 def test_coveritertraverse(self):
 try:
 import gc
@@ -904,8 +924,20 @@
 minitemsize = 8
 tests.append(DoubleTest)
 
-def test_main():
+def test_main(verbose=None):
+ import sys
+
 test_support.run_unittest(*tests)
 
-if __name__=="__main__":
- test_main()
+ # verify reference counting
+ if verbose and hasattr(sys, "gettotalrefcount"):
+ import gc
+ counts = [None] * 5
+ for i in xrange(len(counts)):
+ test_support.run_unittest(*tests)
+ gc.collect()
+ counts[i] = sys.gettotalrefcount()
+ print counts
+
+if __name__ == "__main__":
+ test_main(verbose=True)


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /