mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
SF #1085304: Make array.array pickle-able
This commit is contained in:
parent
e6bdb37e5b
commit
b0900e6a21
3 changed files with 46 additions and 0 deletions
|
@ -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])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue