summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_array.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-12-16 16:23:40 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-12-16 16:23:40 (GMT)
commitb0900e6a217480def244b0b55d718ce705e8e73a (patch)
treeded97348a4d0d9b1fd519acd9b0d1cfad4b9cc86 /Lib/test/test_array.py
parente6bdb37e5bc7d250e17c3d4fef6961e178e02b64 (diff)
downloadcpython-b0900e6a217480def244b0b55d718ce705e8e73a.zip
cpython-b0900e6a217480def244b0b55d718ce705e8e73a.tar.gz
cpython-b0900e6a217480def244b0b55d718ce705e8e73a.tar.bz2
SF #1085304: Make array.array pickle-able
Diffstat (limited to 'Lib/test/test_array.py')
-rwxr-xr-xLib/test/test_array.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index b15298f..c24b41b 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -7,6 +7,10 @@ import unittest
from test import test_support
from weakref import proxy
import array, cStringIO, math
+from cPickle import loads, dumps
+
+class ArraySubclass(array.array):
+ pass
tests = [] # list to accumulate all tests
typecodes = "cubBhHiIlLfd"
@@ -81,6 +85,21 @@ class BaseTest(unittest.TestCase):
self.assertNotEqual(id(a), id(b))
self.assertEqual(a, b)
+ def test_pickle(self):
+ for protocol in (0, 1, 2):
+ a = array.array(self.typecode, self.example)
+ b = loads(dumps(a, protocol))
+ self.assertNotEqual(id(a), id(b))
+ self.assertEqual(a, b)
+
+ a = ArraySubclass(self.typecode, self.example)
+ a.x = 10
+ b = loads(dumps(a, protocol))
+ self.assertNotEqual(id(a), id(b))
+ self.assertEqual(a, b)
+ self.assertEqual(a.x, b.x)
+ self.assertEqual(type(a), type(b))
+
def test_insert(self):
a = array.array(self.typecode, self.example)
a.insert(0, self.example[0])