/brz/remove-bazaar

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