/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4679.3.1 by John Arbash Meinel
Start working on a Keys type.
1
# Copyright (C) 2009 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
17
"""Tests for the StaticTuple type."""
4679.3.1 by John Arbash Meinel
Start working on a Keys type.
18
4759.2.16 by Matt Nordhoff
Add a test
19
import cPickle
4679.3.20 by John Arbash Meinel
Implement tp_traverse, and add a soft dependency on meliae to test it.
20
import gc
4679.3.2 by John Arbash Meinel
Add a get_key() function, which then returns tuples for the given items.
21
import sys
22
4679.3.1 by John Arbash Meinel
Start working on a Keys type.
23
from bzrlib import (
4679.3.40 by John Arbash Meinel
Switch away from the name Key instead start branding as StaticTuple.
24
    _static_tuple_py,
4668.3.1 by John Arbash Meinel
Fix bug #471193, allow tuples into the CHK code.
25
    debug,
4679.3.1 by John Arbash Meinel
Start working on a Keys type.
26
    errors,
4679.3.29 by John Arbash Meinel
Start work on implementing a Key.intern() function.
27
    osutils,
4679.8.3 by John Arbash Meinel
Expose bzrlib.static_tuple.StaticTuple as a thunk
28
    static_tuple,
4679.3.1 by John Arbash Meinel
Start working on a Keys type.
29
    tests,
30
    )
31
32
33
def load_tests(standard_tests, module, loader):
34
    """Parameterize tests for all versions of groupcompress."""
35
    scenarios = [
4679.3.40 by John Arbash Meinel
Switch away from the name Key instead start branding as StaticTuple.
36
        ('python', {'module': _static_tuple_py}),
4679.3.1 by John Arbash Meinel
Start working on a Keys type.
37
    ]
38
    suite = loader.suiteClass()
4913.2.20 by John Arbash Meinel
Change all of the compiled_foo to compiled_foo_feature
39
    if compiled_static_tuple_feature.available():
40
        scenarios.append(('C', {'module':
41
                                compiled_static_tuple_feature.module}))
4679.3.1 by John Arbash Meinel
Start working on a Keys type.
42
    else:
43
        # the compiled module isn't available, so we add a failing test
44
        class FailWithoutFeature(tests.TestCase):
45
            def test_fail(self):
4913.2.20 by John Arbash Meinel
Change all of the compiled_foo to compiled_foo_feature
46
                self.requireFeature(compiled_static_tuple_feature)
4679.3.1 by John Arbash Meinel
Start working on a Keys type.
47
        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
48
    result = tests.multiply_tests(standard_tests, scenarios, suite)
49
    return result
50
51
4913.2.20 by John Arbash Meinel
Change all of the compiled_foo to compiled_foo_feature
52
compiled_static_tuple_feature = tests.ModuleAvailableFeature(
53
                                    'bzrlib._static_tuple_c')
4679.3.1 by John Arbash Meinel
Start working on a Keys type.
54
55
4679.3.29 by John Arbash Meinel
Start work on implementing a Key.intern() function.
56
class _Meliae(tests.Feature):
57
58
    def _probe(self):
59
        try:
60
            from meliae import scanner
61
        except ImportError:
62
            return False
63
        return True
64
65
    def feature_name(self):
66
        return "Meliae - python memory debugger"
67
68
Meliae = _Meliae()
69
70
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
71
class TestStaticTuple(tests.TestCase):
4679.3.16 by John Arbash Meinel
Initial work for a Key class.
72
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
73
    def assertRefcount(self, count, obj):
74
        """Assert that the refcount for obj is what we expect.
75
76
        Note that this automatically adjusts for the fact that calling
77
        assertRefcount actually creates a new pointer, as does calling
78
        sys.getrefcount. So pass the expected value *before* the call.
79
        """
80
        # I don't understand why it is getrefcount()-3 here, but it seems to be
81
        # correct. If I check in the calling function, with:
82
        # self.assertEqual(count, sys.getrefcount(obj)-1)
83
        # Then it works fine. Something about passing it to assertRefcount is
84
        # actually double-incrementing (and decrementing) the refcount
85
        self.assertEqual(count, sys.getrefcount(obj)-3)
86
4679.3.16 by John Arbash Meinel
Initial work for a Key class.
87
    def test_create(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
88
        k = self.module.StaticTuple('foo')
89
        k = self.module.StaticTuple('foo', 'bar')
4679.3.16 by John Arbash Meinel
Initial work for a Key class.
90
91
    def test_create_bad_args(self):
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
92
        args_256 = ['a']*256
4679.3.16 by John Arbash Meinel
Initial work for a Key class.
93
        # too many args
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
94
        self.assertRaises(ValueError, self.module.StaticTuple, *args_256)
95
        args_300 = ['a']*300
96
        self.assertRaises(ValueError, self.module.StaticTuple, *args_300)
4679.3.16 by John Arbash Meinel
Initial work for a Key class.
97
        # not a string
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
98
        self.assertRaises(TypeError, self.module.StaticTuple, object())
4759.2.2 by John Arbash Meinel
Update _static_tuple_py.py with the same concatenation behavior
99
100
    def test_concat(self):
101
        st1 = self.module.StaticTuple('foo')
102
        st2 = self.module.StaticTuple('bar')
103
        st3 = self.module.StaticTuple('foo', 'bar')
104
        st4 = st1 + st2
105
        self.assertEqual(st3, st4)
106
        self.assertIsInstance(st4, self.module.StaticTuple)
107
108
    def test_concat_with_tuple(self):
109
        st1 = self.module.StaticTuple('foo')
110
        t2 = ('bar',)
111
        st3 = self.module.StaticTuple('foo', 'bar')
112
        st4 = self.module.StaticTuple('bar', 'foo')
113
        st5 = st1 + t2
114
        st6 = t2 + st1
115
        self.assertEqual(st3, st5)
116
        self.assertIsInstance(st5, self.module.StaticTuple)
117
        self.assertEqual(st4, st6)
118
        if self.module is _static_tuple_py:
119
            # _static_tuple_py has StaticTuple(tuple), so tuple thinks it
120
            # already knows how to concatenate, as such we can't "inject" our
121
            # own concatenation...
122
            self.assertIsInstance(st6, tuple)
123
        else:
124
            self.assertIsInstance(st6, self.module.StaticTuple)
125
126
    def test_concat_with_bad_tuple(self):
127
        st1 = self.module.StaticTuple('foo')
128
        t2 = (object(),)
4759.2.11 by John Arbash Meinel
Review feedback from Andrew.
129
        # Using st1.__add__ doesn't give the same results as doing the '+' form
130
        self.assertRaises(TypeError, lambda: st1 + t2)
4759.2.5 by John Arbash Meinel
Add a bit more tests.
131
132
    def test_concat_with_non_tuple(self):
133
        st1 = self.module.StaticTuple('foo')
4759.2.11 by John Arbash Meinel
Review feedback from Andrew.
134
        self.assertRaises(TypeError, lambda: st1 + 10)
4679.3.16 by John Arbash Meinel
Initial work for a Key class.
135
        
136
    def test_as_tuple(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
137
        k = self.module.StaticTuple('foo')
4679.3.29 by John Arbash Meinel
Start work on implementing a Key.intern() function.
138
        t = k.as_tuple()
4679.3.16 by John Arbash Meinel
Initial work for a Key class.
139
        self.assertEqual(('foo',), t)
4789.28.3 by John Arbash Meinel
Add a static_tuple.as_tuples() helper.
140
        self.assertIsInstance(t, tuple)
141
        self.assertFalse(isinstance(t, self.module.StaticTuple))
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
142
        k = self.module.StaticTuple('foo', 'bar')
4679.3.29 by John Arbash Meinel
Start work on implementing a Key.intern() function.
143
        t = k.as_tuple()
4679.3.16 by John Arbash Meinel
Initial work for a Key class.
144
        self.assertEqual(('foo', 'bar'), t)
4789.28.3 by John Arbash Meinel
Add a static_tuple.as_tuples() helper.
145
        k2 = self.module.StaticTuple(1, k)
146
        t = k2.as_tuple()
147
        self.assertIsInstance(t, tuple)
148
        # For pickling to work, we need to keep the sub-items as StaticTuple so
149
        # that it knows that they also need to be converted.
150
        self.assertIsInstance(t[1], self.module.StaticTuple)
151
        self.assertEqual((1, ('foo', 'bar')), t)
152
153
    def test_as_tuples(self):
154
        k1 = self.module.StaticTuple('foo', 'bar')
155
        t = static_tuple.as_tuples(k1)
156
        self.assertIsInstance(t, tuple)
157
        self.assertEqual(('foo', 'bar'), t)
158
        k2 = self.module.StaticTuple(1, k1)
159
        t = static_tuple.as_tuples(k2)
160
        self.assertIsInstance(t, tuple)
161
        self.assertIsInstance(t[1], tuple)
162
        self.assertEqual((1, ('foo', 'bar')), t)
163
        mixed = (1, k1)
164
        t = static_tuple.as_tuples(mixed)
165
        self.assertIsInstance(t, tuple)
166
        self.assertIsInstance(t[1], tuple)
167
        self.assertEqual((1, ('foo', 'bar')), t)
4679.3.16 by John Arbash Meinel
Initial work for a Key class.
168
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
169
    def test_len(self):
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
170
        k = self.module.StaticTuple()
171
        self.assertEqual(0, len(k))
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
172
        k = self.module.StaticTuple('foo')
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
173
        self.assertEqual(1, len(k))
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
174
        k = self.module.StaticTuple('foo', 'bar')
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
175
        self.assertEqual(2, len(k))
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
176
        k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'b')
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
177
        self.assertEqual(7, len(k))
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
178
        args = ['foo']*255
179
        k = self.module.StaticTuple(*args)
180
        self.assertEqual(255, len(k))
181
182
    def test_hold_other_static_tuples(self):
183
        k = self.module.StaticTuple('foo', 'bar')
184
        k2 = self.module.StaticTuple(k, k)
185
        self.assertEqual(2, len(k2))
186
        self.assertIs(k, k2[0])
187
        self.assertIs(k, k2[1])
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
188
189
    def test_getitem(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
190
        k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'z')
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
191
        self.assertEqual('foo', k[0])
192
        self.assertEqual('foo', k[0])
193
        self.assertEqual('foo', k[0])
194
        self.assertEqual('z', k[6])
195
        self.assertEqual('z', k[-1])
4679.5.5 by John Arbash Meinel
Review feedback from Andrew Bennetts.
196
        self.assertRaises(IndexError, k.__getitem__, 7)
197
        self.assertRaises(IndexError, k.__getitem__, 256+7)
198
        self.assertRaises(IndexError, k.__getitem__, 12024)
199
        # Python's [] resolver handles the negative arguments, so we can't
200
        # really test StaticTuple_item() with negative values.
201
        self.assertRaises(TypeError, k.__getitem__, 'not-an-int')
202
        self.assertRaises(TypeError, k.__getitem__, '5')
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
203
204
    def test_refcount(self):
205
        f = 'fo' + 'oo'
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
206
        num_refs = sys.getrefcount(f) - 1 #sys.getrefcount() adds one
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
207
        k = self.module.StaticTuple(f)
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
208
        self.assertRefcount(num_refs + 1, f)
209
        b = k[0]
210
        self.assertRefcount(num_refs + 2, f)
211
        b = k[0]
212
        self.assertRefcount(num_refs + 2, f)
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
213
        c = k[0]
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
214
        self.assertRefcount(num_refs + 3, f)
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
215
        del b, c
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
216
        self.assertRefcount(num_refs + 1, f)
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
217
        del k
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
218
        self.assertRefcount(num_refs, f)
4679.3.17 by John Arbash Meinel
Implement some of the sequence items.
219
4679.3.18 by John Arbash Meinel
Copy the hash and richcompare implementations, and add some tests.
220
    def test__repr__(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
221
        k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
4679.3.79 by John Arbash Meinel
Change the repr to print out 'StaticTuple'
222
        self.assertEqual("StaticTuple('foo', 'bar', 'baz', 'bing')", repr(k))
4679.3.18 by John Arbash Meinel
Copy the hash and richcompare implementations, and add some tests.
223
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
224
    def assertCompareEqual(self, k1, k2):
225
        self.assertTrue(k1 == k2)
226
        self.assertTrue(k1 <= k2)
227
        self.assertTrue(k1 >= k2)
228
        self.assertFalse(k1 != k2)
229
        self.assertFalse(k1 < k2)
230
        self.assertFalse(k1 > k2)
231
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
232
    def test_holds_None(self):
233
        k1 = self.module.StaticTuple(None)
4759.2.11 by John Arbash Meinel
Review feedback from Andrew.
234
        # You cannot subclass None anyway
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
235
236
    def test_holds_int(self):
237
        k1 = self.module.StaticTuple(1)
4759.2.11 by John Arbash Meinel
Review feedback from Andrew.
238
        class subint(int):
239
            pass
240
        # But not a subclass, because subint could introduce refcycles
241
        self.assertRaises(TypeError, self.module.StaticTuple, subint(2))
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
242
4759.2.9 by John Arbash Meinel
Implement support for lots of types.
243
    def test_holds_long(self):
244
        k1 = self.module.StaticTuple(2L**65)
4759.2.11 by John Arbash Meinel
Review feedback from Andrew.
245
        class sublong(long):
246
            pass
247
        # But not a subclass
248
        self.assertRaises(TypeError, self.module.StaticTuple, sublong(1))
4759.2.9 by John Arbash Meinel
Implement support for lots of types.
249
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
250
    def test_holds_float(self):
251
        k1 = self.module.StaticTuple(1.2)
4759.2.11 by John Arbash Meinel
Review feedback from Andrew.
252
        class subfloat(float):
253
            pass
254
        self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
255
256
    def test_holds_str(self):
257
        k1 = self.module.StaticTuple('astring')
258
        class substr(str):
259
            pass
260
        self.assertRaises(TypeError, self.module.StaticTuple, substr('a'))
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
261
262
    def test_holds_unicode(self):
263
        k1 = self.module.StaticTuple(u'\xb5')
4759.2.11 by John Arbash Meinel
Review feedback from Andrew.
264
        class subunicode(unicode):
265
            pass
266
        self.assertRaises(TypeError, self.module.StaticTuple,
267
                          subunicode(u'\xb5'))
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
268
269
    def test_hold_bool(self):
270
        k1 = self.module.StaticTuple(True)
271
        k2 = self.module.StaticTuple(False)
4759.2.11 by John Arbash Meinel
Review feedback from Andrew.
272
        # Cannot subclass bool
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
273
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
274
    def test_compare_same_obj(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
275
        k1 = self.module.StaticTuple('foo', 'bar')
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
276
        self.assertCompareEqual(k1, k1)
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
277
        k2 = self.module.StaticTuple(k1, k1)
278
        self.assertCompareEqual(k2, k2)
4759.2.9 by John Arbash Meinel
Implement support for lots of types.
279
        k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
280
                                     k1)
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
281
        self.assertCompareEqual(k3, k3)
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
282
283
    def test_compare_equivalent_obj(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
284
        k1 = self.module.StaticTuple('foo', 'bar')
285
        k2 = self.module.StaticTuple('foo', 'bar')
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
286
        self.assertCompareEqual(k1, k2)
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
287
        k3 = self.module.StaticTuple(k1, k2)
288
        k4 = self.module.StaticTuple(k2, k1)
289
        self.assertCompareEqual(k1, k2)
4759.2.9 by John Arbash Meinel
Implement support for lots of types.
290
        k5 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
291
                                     k1)
292
        k6 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
293
                                     k1)
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
294
        self.assertCompareEqual(k5, k6)
295
        k7 = self.module.StaticTuple(None)
296
        k8 = self.module.StaticTuple(None)
297
        self.assertCompareEqual(k7, k8)
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
298
299
    def test_compare_similar_obj(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
300
        k1 = self.module.StaticTuple('foo' + ' bar', 'bar' + ' baz')
301
        k2 = self.module.StaticTuple('fo' + 'o bar', 'ba' + 'r baz')
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
302
        self.assertCompareEqual(k1, k2)
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
303
        k3 = self.module.StaticTuple('foo ' + 'bar', 'bar ' + 'baz')
304
        k4 = self.module.StaticTuple('f' + 'oo bar', 'b' + 'ar baz')
305
        k5 = self.module.StaticTuple(k1, k2)
306
        k6 = self.module.StaticTuple(k3, k4)
307
        self.assertCompareEqual(k5, k6)
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
308
309
    def assertCompareDifferent(self, k_small, k_big):
310
        self.assertFalse(k_small == k_big)
311
        self.assertFalse(k_small >= k_big)
312
        self.assertFalse(k_small > k_big)
313
        self.assertTrue(k_small != k_big)
314
        self.assertTrue(k_small <= k_big)
315
        self.assertTrue(k_small < k_big)
316
4679.5.8 by John Arbash Meinel
Add some tests that we *can* compare to strings, even if we don't care
317
    def assertCompareNoRelation(self, k1, k2):
318
        """Run the comparison operators, make sure they do something.
319
320
        However, we don't actually care what comes first or second. This is
321
        stuff like cross-class comparisons. We don't want to segfault/raise an
322
        exception, but we don't care about the sort order.
323
        """
324
        self.assertFalse(k1 == k2)
325
        self.assertTrue(k1 != k2)
326
        # Do the comparison, but we don't care about the result
327
        k1 >= k2
328
        k1 > k2
329
        k1 <= k2
330
        k1 < k2
331
4679.3.45 by John Arbash Meinel
Do some work to handle comparison to object that aren't tuples or strings.
332
    def test_compare_vs_none(self):
333
        k1 = self.module.StaticTuple('baz', 'bing')
334
        self.assertCompareDifferent(None, k1)
4679.5.8 by John Arbash Meinel
Add some tests that we *can* compare to strings, even if we don't care
335
    
336
    def test_compare_cross_class(self):
337
        k1 = self.module.StaticTuple('baz', 'bing')
338
        self.assertCompareNoRelation(10, k1)
339
        self.assertCompareNoRelation('baz', k1)
4679.3.45 by John Arbash Meinel
Do some work to handle comparison to object that aren't tuples or strings.
340
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
341
    def test_compare_all_different_same_width(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
342
        k1 = self.module.StaticTuple('baz', 'bing')
343
        k2 = self.module.StaticTuple('foo', 'bar')
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
344
        self.assertCompareDifferent(k1, k2)
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
345
        k3 = self.module.StaticTuple(k1, k2)
346
        k4 = self.module.StaticTuple(k2, k1)
347
        self.assertCompareDifferent(k3, k4)
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
348
        k5 = self.module.StaticTuple(1)
349
        k6 = self.module.StaticTuple(2)
350
        self.assertCompareDifferent(k5, k6)
351
        k7 = self.module.StaticTuple(1.2)
352
        k8 = self.module.StaticTuple(2.4)
353
        self.assertCompareDifferent(k7, k8)
354
        k9 = self.module.StaticTuple(u's\xb5')
355
        k10 = self.module.StaticTuple(u's\xe5')
356
        self.assertCompareDifferent(k9, k10)
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
357
358
    def test_compare_some_different(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
359
        k1 = self.module.StaticTuple('foo', 'bar')
360
        k2 = self.module.StaticTuple('foo', 'zzz')
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
361
        self.assertCompareDifferent(k1, k2)
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
362
        k3 = self.module.StaticTuple(k1, k1)
363
        k4 = self.module.StaticTuple(k1, k2)
364
        self.assertCompareDifferent(k3, k4)
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
365
        k5 = self.module.StaticTuple('foo', None)
366
        self.assertCompareDifferent(k5, k1)
367
        self.assertCompareDifferent(k5, k2)
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
368
369
    def test_compare_diff_width(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
370
        k1 = self.module.StaticTuple('foo')
371
        k2 = self.module.StaticTuple('foo', 'bar')
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
372
        self.assertCompareDifferent(k1, k2)
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
373
        k3 = self.module.StaticTuple(k1)
374
        k4 = self.module.StaticTuple(k1, k2)
375
        self.assertCompareDifferent(k3, k4)
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
376
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
377
    def test_compare_different_types(self):
378
        k1 = self.module.StaticTuple('foo', 'bar')
4759.2.9 by John Arbash Meinel
Implement support for lots of types.
379
        k2 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
380
                                     k1)
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
381
        self.assertCompareNoRelation(k1, k2)
382
        k3 = self.module.StaticTuple('foo')
383
        self.assertCompareDifferent(k3, k1)
384
        k4 = self.module.StaticTuple(None)
385
        self.assertCompareDifferent(k4, k1)
386
        k5 = self.module.StaticTuple(1)
387
        self.assertCompareNoRelation(k1, k5)
388
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
389
    def test_compare_to_tuples(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
390
        k1 = self.module.StaticTuple('foo')
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
391
        self.assertCompareEqual(k1, ('foo',))
392
        self.assertCompareEqual(('foo',), k1)
393
        self.assertCompareDifferent(k1, ('foo', 'bar'))
394
        self.assertCompareDifferent(k1, ('foo', 10))
395
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
396
        k2 = self.module.StaticTuple('foo', 'bar')
4679.3.21 by John Arbash Meinel
Implement Key_richcompare directly, rather than thunking to tuples.
397
        self.assertCompareEqual(k2, ('foo', 'bar'))
398
        self.assertCompareEqual(('foo', 'bar'), k2)
399
        self.assertCompareDifferent(k2, ('foo', 'zzz'))
400
        self.assertCompareDifferent(('foo',), k2)
401
        self.assertCompareDifferent(('foo', 'aaa'), k2)
402
        self.assertCompareDifferent(('baz', 'bing'), k2)
403
        self.assertCompareDifferent(('foo', 10), k2)
4679.3.18 by John Arbash Meinel
Copy the hash and richcompare implementations, and add some tests.
404
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
405
        k3 = self.module.StaticTuple(k1, k2)
406
        self.assertCompareEqual(k3, (('foo',), ('foo', 'bar')))
407
        self.assertCompareEqual((('foo',), ('foo', 'bar')), k3)
408
        self.assertCompareEqual(k3, (k1, ('foo', 'bar')))
409
        self.assertCompareEqual((k1, ('foo', 'bar')), k3)
410
4679.8.11 by John Arbash Meinel
Handle the case where the recursive call ends up returning NotImplemented.
411
    def test_compare_mixed_depths(self):
412
        stuple = self.module.StaticTuple
4679.8.13 by John Arbash Meinel
clean up the test case a little bit.
413
        k1 = stuple(stuple('a',), stuple('b',))
414
        k2 = stuple(stuple(stuple('c',), stuple('d',)),
415
                    stuple('b',))
4679.8.11 by John Arbash Meinel
Handle the case where the recursive call ends up returning NotImplemented.
416
        # This requires comparing a StaticTuple to a 'string', and then
417
        # interpreting that value in the next higher StaticTuple. This used to
418
        # generate a PyErr_BadIternalCall. We now fall back to *something*.
419
        self.assertCompareNoRelation(k1, k2)
420
4679.3.18 by John Arbash Meinel
Copy the hash and richcompare implementations, and add some tests.
421
    def test_hash(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
422
        k = self.module.StaticTuple('foo')
4679.3.18 by John Arbash Meinel
Copy the hash and richcompare implementations, and add some tests.
423
        self.assertEqual(hash(k), hash(('foo',)))
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
424
        k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
4679.3.18 by John Arbash Meinel
Copy the hash and richcompare implementations, and add some tests.
425
        as_tuple = ('foo', 'bar', 'baz', 'bing')
426
        self.assertEqual(hash(k), hash(as_tuple))
427
        x = {k: 'foo'}
428
        # Because k == , it replaces the slot, rather than having both
429
        # present in the dict.
430
        self.assertEqual('foo', x[as_tuple])
431
        x[as_tuple] = 'bar'
432
        self.assertEqual({as_tuple: 'bar'}, x)
433
4679.3.42 by John Arbash Meinel
Implement comparison support when using nested StaticTuple objects.
434
        k2 = self.module.StaticTuple(k)
435
        as_tuple2 = (('foo', 'bar', 'baz', 'bing'),)
436
        self.assertEqual(hash(k2), hash(as_tuple2))
437
4759.2.9 by John Arbash Meinel
Implement support for lots of types.
438
        k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
439
                                     k)
440
        as_tuple3 = ('foo', 1, None, u'\xb5', 1.2, 2**65, True, k)
4759.2.8 by John Arbash Meinel
Set up a test suite for hash() and richcompare against lots of acceptable types.
441
        self.assertEqual(hash(as_tuple3), hash(k3))
442
4679.3.19 by John Arbash Meinel
implement slicing as a tuple thunk.
443
    def test_slice(self):
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
444
        k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
4679.3.19 by John Arbash Meinel
implement slicing as a tuple thunk.
445
        self.assertEqual(('foo', 'bar'), k[:2])
446
        self.assertEqual(('baz',), k[2:-1])
4679.5.5 by John Arbash Meinel
Review feedback from Andrew Bennetts.
447
        try:
448
            val = k[::2]
449
        except TypeError:
450
            # C implementation raises a TypeError, we don't need the
451
            # implementation yet, so allow this to pass
452
            pass
453
        else:
454
            # Python implementation uses a regular Tuple, so make sure it gives
455
            # the right result
456
            self.assertEqual(('foo', 'baz'), val)
4679.3.19 by John Arbash Meinel
implement slicing as a tuple thunk.
457
4679.3.20 by John Arbash Meinel
Implement tp_traverse, and add a soft dependency on meliae to test it.
458
    def test_referents(self):
459
        # We implement tp_traverse so that things like 'meliae' can measure the
460
        # amount of referenced memory. Unfortunately gc.get_referents() first
4679.5.5 by John Arbash Meinel
Review feedback from Andrew Bennetts.
461
        # checks the IS_GC flag before it traverses anything. We could write a
462
        # helper func, but that won't work for the generic implementation...
4679.3.29 by John Arbash Meinel
Start work on implementing a Key.intern() function.
463
        self.requireFeature(Meliae)
464
        from meliae import scanner
4679.3.20 by John Arbash Meinel
Implement tp_traverse, and add a soft dependency on meliae to test it.
465
        strs = ['foo', 'bar', 'baz', 'bing']
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
466
        k = self.module.StaticTuple(*strs)
4679.3.45 by John Arbash Meinel
Do some work to handle comparison to object that aren't tuples or strings.
467
        if self.module is _static_tuple_py:
4679.3.78 by John Arbash Meinel
Change the pure-python version of StaticTuple
468
            refs = strs + [self.module.StaticTuple]
4679.3.29 by John Arbash Meinel
Start work on implementing a Key.intern() function.
469
        else:
4679.3.78 by John Arbash Meinel
Change the pure-python version of StaticTuple
470
            refs = strs
471
        self.assertEqual(sorted(refs), sorted(scanner.get_referents(k)))
4679.3.20 by John Arbash Meinel
Implement tp_traverse, and add a soft dependency on meliae to test it.
472
4679.3.45 by John Arbash Meinel
Do some work to handle comparison to object that aren't tuples or strings.
473
    def test_nested_referents(self):
474
        self.requireFeature(Meliae)
4679.3.78 by John Arbash Meinel
Change the pure-python version of StaticTuple
475
        from meliae import scanner
476
        strs = ['foo', 'bar', 'baz', 'bing']
477
        k1 = self.module.StaticTuple(*strs[:2])
478
        k2 = self.module.StaticTuple(*strs[2:])
479
        k3 = self.module.StaticTuple(k1, k2)
480
        refs = [k1, k2]
481
        if self.module is _static_tuple_py:
482
            refs.append(self.module.StaticTuple)
483
        self.assertEqual(sorted(refs),
484
                         sorted(scanner.get_referents(k3)))
4679.3.45 by John Arbash Meinel
Do some work to handle comparison to object that aren't tuples or strings.
485
4679.3.44 by John Arbash Meinel
Special case the empty tuple as a singleton.
486
    def test_empty_is_singleton(self):
487
        key = self.module.StaticTuple()
488
        self.assertIs(key, self.module._empty_tuple)
489
4679.3.29 by John Arbash Meinel
Start work on implementing a Key.intern() function.
490
    def test_intern(self):
491
        unique_str1 = 'unique str ' + osutils.rand_chars(20)
492
        unique_str2 = 'unique str ' + osutils.rand_chars(20)
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
493
        key = self.module.StaticTuple(unique_str1, unique_str2)
4679.3.51 by John Arbash Meinel
Add a _static_tuple_c.pxd file to define the C api to pyrex code.
494
        self.assertFalse(key in self.module._interned_tuples)
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
495
        key2 = self.module.StaticTuple(unique_str1, unique_str2)
4679.3.29 by John Arbash Meinel
Start work on implementing a Key.intern() function.
496
        self.assertEqual(key, key2)
497
        self.assertIsNot(key, key2)
4679.3.33 by John Arbash Meinel
Change Key away from being a PyVarObject.
498
        key3 = key.intern()
499
        self.assertIs(key, key3)
4679.3.51 by John Arbash Meinel
Add a _static_tuple_c.pxd file to define the C api to pyrex code.
500
        self.assertTrue(key in self.module._interned_tuples)
501
        self.assertEqual(key, self.module._interned_tuples[key])
4679.3.33 by John Arbash Meinel
Change Key away from being a PyVarObject.
502
        key2 = key2.intern()
503
        self.assertIs(key, key2)
4679.3.29 by John Arbash Meinel
Start work on implementing a Key.intern() function.
504
4679.3.33 by John Arbash Meinel
Change Key away from being a PyVarObject.
505
    def test__c_intern_handles_refcount(self):
4679.3.40 by John Arbash Meinel
Switch away from the name Key instead start branding as StaticTuple.
506
        if self.module is _static_tuple_py:
4679.3.33 by John Arbash Meinel
Change Key away from being a PyVarObject.
507
            return # Not applicable
508
        unique_str1 = 'unique str ' + osutils.rand_chars(20)
509
        unique_str2 = 'unique str ' + osutils.rand_chars(20)
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
510
        key = self.module.StaticTuple(unique_str1, unique_str2)
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
511
        self.assertRefcount(1, key)
4679.3.51 by John Arbash Meinel
Add a _static_tuple_c.pxd file to define the C api to pyrex code.
512
        self.assertFalse(key in self.module._interned_tuples)
4679.3.35 by John Arbash Meinel
Work on making intern() not generate immortal Key objects.
513
        self.assertFalse(key._is_interned())
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
514
        key2 = self.module.StaticTuple(unique_str1, unique_str2)
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
515
        self.assertRefcount(1, key)
516
        self.assertRefcount(1, key2)
4679.3.33 by John Arbash Meinel
Change Key away from being a PyVarObject.
517
        self.assertEqual(key, key2)
518
        self.assertIsNot(key, key2)
4679.3.30 by John Arbash Meinel
Interning with a regular 'dict' is a tradeoff for bzr.dev of:
519
520
        key3 = key.intern()
521
        self.assertIs(key, key3)
4679.3.51 by John Arbash Meinel
Add a _static_tuple_c.pxd file to define the C api to pyrex code.
522
        self.assertTrue(key in self.module._interned_tuples)
523
        self.assertEqual(key, self.module._interned_tuples[key])
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
524
        # key and key3, but we 'hide' the one in _interned_tuples
525
        self.assertRefcount(2, key)
4679.3.30 by John Arbash Meinel
Interning with a regular 'dict' is a tradeoff for bzr.dev of:
526
        del key3
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
527
        self.assertRefcount(1, key)
4679.3.35 by John Arbash Meinel
Work on making intern() not generate immortal Key objects.
528
        self.assertTrue(key._is_interned())
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
529
        self.assertRefcount(1, key2)
530
        key3 = key2.intern()
531
        # key3 now points to key as well, and *not* to key2
532
        self.assertRefcount(2, key)
533
        self.assertRefcount(1, key2)
534
        self.assertIs(key, key3)
535
        self.assertIsNot(key3, key2)
536
        del key2
537
        del key3
538
        self.assertRefcount(1, key)
4679.3.38 by John Arbash Meinel
add a test that Key.intern() doesn't create an immortal object.
539
540
    def test__c_keys_are_not_immortal(self):
4679.3.40 by John Arbash Meinel
Switch away from the name Key instead start branding as StaticTuple.
541
        if self.module is _static_tuple_py:
4679.3.38 by John Arbash Meinel
add a test that Key.intern() doesn't create an immortal object.
542
            return # Not applicable
543
        unique_str1 = 'unique str ' + osutils.rand_chars(20)
544
        unique_str2 = 'unique str ' + osutils.rand_chars(20)
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
545
        key = self.module.StaticTuple(unique_str1, unique_str2)
4679.3.51 by John Arbash Meinel
Add a _static_tuple_c.pxd file to define the C api to pyrex code.
546
        self.assertFalse(key in self.module._interned_tuples)
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
547
        self.assertRefcount(1, key)
4679.3.38 by John Arbash Meinel
add a test that Key.intern() doesn't create an immortal object.
548
        key = key.intern()
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
549
        self.assertRefcount(1, key)
4679.3.51 by John Arbash Meinel
Add a _static_tuple_c.pxd file to define the C api to pyrex code.
550
        self.assertTrue(key in self.module._interned_tuples)
4679.3.38 by John Arbash Meinel
add a test that Key.intern() doesn't create an immortal object.
551
        self.assertTrue(key._is_interned())
552
        del key
553
        # Create a new entry, which would point to the same location
4679.3.41 by John Arbash Meinel
Finish switching the naming to StaticTuple.
554
        key = self.module.StaticTuple(unique_str1, unique_str2)
4679.3.81 by John Arbash Meinel
Fix up _simple_set_pyx.pyx to be compatible with pyrex again.
555
        self.assertRefcount(1, key)
4679.3.51 by John Arbash Meinel
Add a _static_tuple_c.pxd file to define the C api to pyrex code.
556
        # This old entry in _interned_tuples should be gone
557
        self.assertFalse(key in self.module._interned_tuples)
4679.3.38 by John Arbash Meinel
add a test that Key.intern() doesn't create an immortal object.
558
        self.assertFalse(key._is_interned())
4679.3.47 by John Arbash Meinel
Work out how to expose the C api using the Python PyCObject interface.
559
560
    def test__c_has_C_API(self):
561
        if self.module is _static_tuple_py:
562
            return
563
        self.assertIsNot(None, self.module._C_API)
4679.8.3 by John Arbash Meinel
Expose bzrlib.static_tuple.StaticTuple as a thunk
564
4739.4.1 by John Arbash Meinel
Implement StaticTuple.from_sequence()
565
    def test_from_sequence_tuple(self):
566
        st = self.module.StaticTuple.from_sequence(('foo', 'bar'))
567
        self.assertIsInstance(st, self.module.StaticTuple)
568
        self.assertEqual(('foo', 'bar'), st)
569
570
    def test_from_sequence_str(self):
571
        st = self.module.StaticTuple.from_sequence('foo')
572
        self.assertIsInstance(st, self.module.StaticTuple)
573
        self.assertEqual(('f', 'o', 'o'), st)
574
575
    def test_from_sequence_list(self):
576
        st = self.module.StaticTuple.from_sequence(['foo', 'bar'])
577
        self.assertIsInstance(st, self.module.StaticTuple)
578
        self.assertEqual(('foo', 'bar'), st)
579
580
    def test_from_sequence_static_tuple(self):
581
        st = self.module.StaticTuple('foo', 'bar')
582
        st2 = self.module.StaticTuple.from_sequence(st)
583
        # If the source is a StaticTuple already, we return the exact object
584
        self.assertIs(st, st2)
585
586
    def test_from_sequence_not_sequence(self):
587
        self.assertRaises(TypeError,
588
                          self.module.StaticTuple.from_sequence, object())
4771.2.2 by John Arbash Meinel
Clean up the C code a bit, using a goto.
589
        self.assertRaises(TypeError,
590
                          self.module.StaticTuple.from_sequence, 10)
4739.4.1 by John Arbash Meinel
Implement StaticTuple.from_sequence()
591
592
    def test_from_sequence_incorrect_args(self):
593
        self.assertRaises(TypeError,
594
                          self.module.StaticTuple.from_sequence, object(), 'a')
595
        self.assertRaises(TypeError,
596
                          self.module.StaticTuple.from_sequence, foo='a')
4739.4.2 by John Arbash Meinel
Merge bzr.dev resolve test conflict.
597
4771.2.1 by Matt Nordhoff
_static_tuple_c.StaticTuple.from_sequence() now supports arbitrary iterables (by converting them to tuples first).
598
    def test_from_sequence_iterable(self):
4771.2.2 by John Arbash Meinel
Clean up the C code a bit, using a goto.
599
        st = self.module.StaticTuple.from_sequence(iter(['foo', 'bar']))
600
        self.assertIsInstance(st, self.module.StaticTuple)
601
        self.assertEqual(('foo', 'bar'), st)
602
603
    def test_from_sequence_generator(self):
604
        def generate_tuple():
605
            yield 'foo'
606
            yield 'bar'
607
        st = self.module.StaticTuple.from_sequence(generate_tuple())
4771.2.1 by Matt Nordhoff
_static_tuple_c.StaticTuple.from_sequence() now supports arbitrary iterables (by converting them to tuples first).
608
        self.assertIsInstance(st, self.module.StaticTuple)
609
        self.assertEqual(('foo', 'bar'), st)
610
4759.2.16 by Matt Nordhoff
Add a test
611
    def test_pickle(self):
612
        st = self.module.StaticTuple('foo', 'bar')
613
        pickled = cPickle.dumps(st)
614
        unpickled = cPickle.loads(pickled)
615
        self.assertEqual(unpickled, st)
4759.2.20 by Matt Nordhoff
Review: Add a Py_INCREF, and test pickling a nested StaticTuple.
616
617
    def test_pickle_empty(self):
4759.2.17 by Matt Nordhoff
Test pickling the empty StaticTuple too
618
        st = self.module.StaticTuple()
619
        pickled = cPickle.dumps(st)
620
        unpickled = cPickle.loads(pickled)
621
        self.assertIs(st, unpickled)
4759.2.16 by Matt Nordhoff
Add a test
622
4759.2.20 by Matt Nordhoff
Review: Add a Py_INCREF, and test pickling a nested StaticTuple.
623
    def test_pickle_nested(self):
624
        st = self.module.StaticTuple('foo', self.module.StaticTuple('bar'))
625
        pickled = cPickle.dumps(st)
626
        unpickled = cPickle.loads(pickled)
627
        self.assertEqual(unpickled, st)
628
4679.8.3 by John Arbash Meinel
Expose bzrlib.static_tuple.StaticTuple as a thunk
629
    def test_static_tuple_thunk(self):
630
        # Make sure the right implementation is available from
631
        # bzrlib.static_tuple.StaticTuple.
632
        if self.module is _static_tuple_py:
4913.2.20 by John Arbash Meinel
Change all of the compiled_foo to compiled_foo_feature
633
            if compiled_static_tuple_feature.available():
4679.8.3 by John Arbash Meinel
Expose bzrlib.static_tuple.StaticTuple as a thunk
634
                # We will be using the C version
635
                return
4739.4.2 by John Arbash Meinel
Merge bzr.dev resolve test conflict.
636
        self.assertIs(static_tuple.StaticTuple,
4679.8.3 by John Arbash Meinel
Expose bzrlib.static_tuple.StaticTuple as a thunk
637
                      self.module.StaticTuple)
4668.3.1 by John Arbash Meinel
Fix bug #471193, allow tuples into the CHK code.
638
639
640
class TestEnsureStaticTuple(tests.TestCase):
641
642
    def test_is_static_tuple(self):
643
        st = static_tuple.StaticTuple('foo')
644
        st2 = static_tuple.expect_static_tuple(st)
645
        self.assertIs(st, st2)
646
647
    def test_is_tuple(self):
648
        t = ('foo',)
649
        st = static_tuple.expect_static_tuple(t)
650
        self.assertIsInstance(st, static_tuple.StaticTuple)
651
        self.assertEqual(t, st)
652
653
    def test_flagged_is_static_tuple(self):
654
        debug.debug_flags.add('static_tuple')
655
        st = static_tuple.StaticTuple('foo')
656
        st2 = static_tuple.expect_static_tuple(st)
657
        self.assertIs(st, st2)
658
659
    def test_flagged_is_tuple(self):
660
        debug.debug_flags.add('static_tuple')
661
        t = ('foo',)
662
        self.assertRaises(TypeError, static_tuple.expect_static_tuple, t)