~pythonregexp2.7/python/issue2636-12

« back to all changes in this revision

Viewing changes to Lib/test/test_collections.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:52:42 UTC
  • mfrom: (39033.1.3 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609145242-9m268zc6u87rp1vp
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import unittest, doctest
2
2
from test import test_support
3
3
from collections import namedtuple
 
4
import pickle, cPickle, copy
4
5
from collections import Hashable, Iterable, Iterator
5
6
from collections import Sized, Container, Callable
6
7
from collections import Set, MutableSet
7
8
from collections import Mapping, MutableMapping
8
9
from collections import Sequence, MutableSequence
9
10
 
 
11
TestNT = namedtuple('TestNT', 'x y z')    # type used for pickle tests
10
12
 
11
13
class TestNamedTuple(unittest.TestCase):
12
14
 
108
110
        self.assertEqual(Dot(1)._replace(d=999), (999,))
109
111
        self.assertEqual(Dot(1)._fields, ('d',))
110
112
 
111
 
        n = 10000
 
113
        n = 5000
112
114
        import string, random
113
115
        names = list(set(''.join([random.choice(string.ascii_letters)
114
116
                                  for j in range(10)]) for i in range(n)))
130
132
        self.assertEqual(b2, tuple(b2_expected))
131
133
        self.assertEqual(b._fields, tuple(names))
132
134
 
 
135
    def test_pickle(self):
 
136
        p = TestNT(x=10, y=20, z=30)
 
137
        for module in pickle, cPickle:
 
138
            loads = getattr(module, 'loads')
 
139
            dumps = getattr(module, 'dumps')
 
140
            for protocol in -1, 0, 1, 2:
 
141
                q = loads(dumps(p, protocol))
 
142
                self.assertEqual(p, q)
 
143
                self.assertEqual(p._fields, q._fields)
 
144
 
 
145
    def test_copy(self):
 
146
        p = TestNT(x=10, y=20, z=30)
 
147
        for copier in copy.copy, copy.deepcopy:
 
148
            q = copier(p)
 
149
            self.assertEqual(p, q)
 
150
            self.assertEqual(p._fields, q._fields)
 
151
 
133
152
class TestOneTrickPonyABCs(unittest.TestCase):
134
153
 
135
154
    def test_Hashable(self):