summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-08-29 07:50:43 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-08-29 07:50:43 (GMT)
commit6ab78cd0c055462af4f5a6c59b9f310a83734c45 (patch)
treee997501de3a39f1e79a77ecf559000dee5ebf5f7 /Lib
parentdf7a208ff70a66f4384252d12768dbd9e7c60204 (diff)
downloadcpython-6ab78cd0c055462af4f5a6c59b9f310a83734c45.zip
cpython-6ab78cd0c055462af4f5a6c59b9f310a83734c45.tar.gz
cpython-6ab78cd0c055462af4f5a6c59b9f310a83734c45.tar.bz2
SF feature request #992967: array.array objects should support sequences.
Made the constructor accept general iterables.
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/test/test_array.py38
1 files changed, 35 insertions, 3 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index d03618d..b15298f 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -600,6 +600,26 @@ class BaseTest(unittest.TestCase):
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 @@ class DoubleTest(FPTest):
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)