1
# Copyright (C) 2009 Canonical Ltd
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.
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.
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
17
"""Tests for the StaticTuple type."""
33
def load_tests(standard_tests, module, loader):
34
"""Parameterize tests for all versions of groupcompress."""
36
('python', {'module': _static_tuple_py}),
38
suite = loader.suiteClass()
39
if compiled_static_tuple_feature.available():
40
scenarios.append(('C', {'module':
41
compiled_static_tuple_feature.module}))
43
# the compiled module isn't available, so we add a failing test
44
class FailWithoutFeature(tests.TestCase):
46
self.requireFeature(compiled_static_tuple_feature)
47
suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
48
result = tests.multiply_tests(standard_tests, scenarios, suite)
52
compiled_static_tuple_feature = tests.ModuleAvailableFeature(
53
'bzrlib._static_tuple_c')
56
class _Meliae(tests.Feature):
60
from meliae import scanner
65
def feature_name(self):
66
return "Meliae - python memory debugger"
71
class TestStaticTuple(tests.TestCase):
73
def assertRefcount(self, count, obj):
74
"""Assert that the refcount for obj is what we expect.
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.
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)
87
def test_create(self):
88
k = self.module.StaticTuple('foo')
89
k = self.module.StaticTuple('foo', 'bar')
91
def test_create_bad_args(self):
94
self.assertRaises(ValueError, self.module.StaticTuple, *args_256)
96
self.assertRaises(ValueError, self.module.StaticTuple, *args_300)
98
self.assertRaises(TypeError, self.module.StaticTuple, object())
100
def test_concat(self):
101
st1 = self.module.StaticTuple('foo')
102
st2 = self.module.StaticTuple('bar')
103
st3 = self.module.StaticTuple('foo', 'bar')
105
self.assertEqual(st3, st4)
106
self.assertIsInstance(st4, self.module.StaticTuple)
108
def test_concat_with_tuple(self):
109
st1 = self.module.StaticTuple('foo')
111
st3 = self.module.StaticTuple('foo', 'bar')
112
st4 = self.module.StaticTuple('bar', 'foo')
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)
124
self.assertIsInstance(st6, self.module.StaticTuple)
126
def test_concat_with_bad_tuple(self):
127
st1 = self.module.StaticTuple('foo')
129
# Using st1.__add__ doesn't give the same results as doing the '+' form
130
self.assertRaises(TypeError, lambda: st1 + t2)
132
def test_concat_with_non_tuple(self):
133
st1 = self.module.StaticTuple('foo')
134
self.assertRaises(TypeError, lambda: st1 + 10)
136
def test_as_tuple(self):
137
k = self.module.StaticTuple('foo')
139
self.assertEqual(('foo',), t)
140
self.assertIsInstance(t, tuple)
141
self.assertFalse(isinstance(t, self.module.StaticTuple))
142
k = self.module.StaticTuple('foo', 'bar')
144
self.assertEqual(('foo', 'bar'), t)
145
k2 = self.module.StaticTuple(1, k)
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)
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)
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)
170
k = self.module.StaticTuple()
171
self.assertEqual(0, len(k))
172
k = self.module.StaticTuple('foo')
173
self.assertEqual(1, len(k))
174
k = self.module.StaticTuple('foo', 'bar')
175
self.assertEqual(2, len(k))
176
k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'b')
177
self.assertEqual(7, len(k))
179
k = self.module.StaticTuple(*args)
180
self.assertEqual(255, len(k))
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])
189
def test_getitem(self):
190
k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'z')
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])
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')
204
def test_refcount(self):
206
num_refs = sys.getrefcount(f) - 1 #sys.getrefcount() adds one
207
k = self.module.StaticTuple(f)
208
self.assertRefcount(num_refs + 1, f)
210
self.assertRefcount(num_refs + 2, f)
212
self.assertRefcount(num_refs + 2, f)
214
self.assertRefcount(num_refs + 3, f)
216
self.assertRefcount(num_refs + 1, f)
218
self.assertRefcount(num_refs, f)
220
def test__repr__(self):
221
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
222
self.assertEqual("StaticTuple('foo', 'bar', 'baz', 'bing')", repr(k))
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)
232
def test_holds_None(self):
233
k1 = self.module.StaticTuple(None)
234
# You cannot subclass None anyway
236
def test_holds_int(self):
237
k1 = self.module.StaticTuple(1)
240
# But not a subclass, because subint could introduce refcycles
241
self.assertRaises(TypeError, self.module.StaticTuple, subint(2))
243
def test_holds_long(self):
244
k1 = self.module.StaticTuple(2L**65)
248
self.assertRaises(TypeError, self.module.StaticTuple, sublong(1))
250
def test_holds_float(self):
251
k1 = self.module.StaticTuple(1.2)
252
class subfloat(float):
254
self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
256
def test_holds_str(self):
257
k1 = self.module.StaticTuple('astring')
260
self.assertRaises(TypeError, self.module.StaticTuple, substr('a'))
262
def test_holds_unicode(self):
263
k1 = self.module.StaticTuple(u'\xb5')
264
class subunicode(unicode):
266
self.assertRaises(TypeError, self.module.StaticTuple,
269
def test_hold_bool(self):
270
k1 = self.module.StaticTuple(True)
271
k2 = self.module.StaticTuple(False)
272
# Cannot subclass bool
274
def test_compare_same_obj(self):
275
k1 = self.module.StaticTuple('foo', 'bar')
276
self.assertCompareEqual(k1, k1)
277
k2 = self.module.StaticTuple(k1, k1)
278
self.assertCompareEqual(k2, k2)
279
k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
281
self.assertCompareEqual(k3, k3)
283
def test_compare_equivalent_obj(self):
284
k1 = self.module.StaticTuple('foo', 'bar')
285
k2 = self.module.StaticTuple('foo', 'bar')
286
self.assertCompareEqual(k1, k2)
287
k3 = self.module.StaticTuple(k1, k2)
288
k4 = self.module.StaticTuple(k2, k1)
289
self.assertCompareEqual(k1, k2)
290
k5 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
292
k6 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
294
self.assertCompareEqual(k5, k6)
295
k7 = self.module.StaticTuple(None)
296
k8 = self.module.StaticTuple(None)
297
self.assertCompareEqual(k7, k8)
299
def test_compare_similar_obj(self):
300
k1 = self.module.StaticTuple('foo' + ' bar', 'bar' + ' baz')
301
k2 = self.module.StaticTuple('fo' + 'o bar', 'ba' + 'r baz')
302
self.assertCompareEqual(k1, k2)
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)
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)
317
def assertCompareNoRelation(self, k1, k2):
318
"""Run the comparison operators, make sure they do something.
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.
324
self.assertFalse(k1 == k2)
325
self.assertTrue(k1 != k2)
326
# Do the comparison, but we don't care about the result
332
def test_compare_vs_none(self):
333
k1 = self.module.StaticTuple('baz', 'bing')
334
self.assertCompareDifferent(None, k1)
336
def test_compare_cross_class(self):
337
k1 = self.module.StaticTuple('baz', 'bing')
338
self.assertCompareNoRelation(10, k1)
339
self.assertCompareNoRelation('baz', k1)
341
def test_compare_all_different_same_width(self):
342
k1 = self.module.StaticTuple('baz', 'bing')
343
k2 = self.module.StaticTuple('foo', 'bar')
344
self.assertCompareDifferent(k1, k2)
345
k3 = self.module.StaticTuple(k1, k2)
346
k4 = self.module.StaticTuple(k2, k1)
347
self.assertCompareDifferent(k3, k4)
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)
358
def test_compare_some_different(self):
359
k1 = self.module.StaticTuple('foo', 'bar')
360
k2 = self.module.StaticTuple('foo', 'zzz')
361
self.assertCompareDifferent(k1, k2)
362
k3 = self.module.StaticTuple(k1, k1)
363
k4 = self.module.StaticTuple(k1, k2)
364
self.assertCompareDifferent(k3, k4)
365
k5 = self.module.StaticTuple('foo', None)
366
self.assertCompareDifferent(k5, k1)
367
self.assertCompareDifferent(k5, k2)
369
def test_compare_diff_width(self):
370
k1 = self.module.StaticTuple('foo')
371
k2 = self.module.StaticTuple('foo', 'bar')
372
self.assertCompareDifferent(k1, k2)
373
k3 = self.module.StaticTuple(k1)
374
k4 = self.module.StaticTuple(k1, k2)
375
self.assertCompareDifferent(k3, k4)
377
def test_compare_different_types(self):
378
k1 = self.module.StaticTuple('foo', 'bar')
379
k2 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
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)
389
def test_compare_to_tuples(self):
390
k1 = self.module.StaticTuple('foo')
391
self.assertCompareEqual(k1, ('foo',))
392
self.assertCompareEqual(('foo',), k1)
393
self.assertCompareDifferent(k1, ('foo', 'bar'))
394
self.assertCompareDifferent(k1, ('foo', 10))
396
k2 = self.module.StaticTuple('foo', 'bar')
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)
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)
411
def test_compare_mixed_depths(self):
412
stuple = self.module.StaticTuple
413
k1 = stuple(stuple('a',), stuple('b',))
414
k2 = stuple(stuple(stuple('c',), stuple('d',)),
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)
422
k = self.module.StaticTuple('foo')
423
self.assertEqual(hash(k), hash(('foo',)))
424
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
425
as_tuple = ('foo', 'bar', 'baz', 'bing')
426
self.assertEqual(hash(k), hash(as_tuple))
428
# Because k == , it replaces the slot, rather than having both
429
# present in the dict.
430
self.assertEqual('foo', x[as_tuple])
432
self.assertEqual({as_tuple: 'bar'}, x)
434
k2 = self.module.StaticTuple(k)
435
as_tuple2 = (('foo', 'bar', 'baz', 'bing'),)
436
self.assertEqual(hash(k2), hash(as_tuple2))
438
k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
440
as_tuple3 = ('foo', 1, None, u'\xb5', 1.2, 2**65, True, k)
441
self.assertEqual(hash(as_tuple3), hash(k3))
443
def test_slice(self):
444
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
445
self.assertEqual(('foo', 'bar'), k[:2])
446
self.assertEqual(('baz',), k[2:-1])
450
# C implementation raises a TypeError, we don't need the
451
# implementation yet, so allow this to pass
454
# Python implementation uses a regular Tuple, so make sure it gives
456
self.assertEqual(('foo', 'baz'), val)
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
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...
463
self.requireFeature(Meliae)
464
from meliae import scanner
465
strs = ['foo', 'bar', 'baz', 'bing']
466
k = self.module.StaticTuple(*strs)
467
if self.module is _static_tuple_py:
468
refs = strs + [self.module.StaticTuple]
471
self.assertEqual(sorted(refs), sorted(scanner.get_referents(k)))
473
def test_nested_referents(self):
474
self.requireFeature(Meliae)
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)
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)))
486
def test_empty_is_singleton(self):
487
key = self.module.StaticTuple()
488
self.assertIs(key, self.module._empty_tuple)
490
def test_intern(self):
491
unique_str1 = 'unique str ' + osutils.rand_chars(20)
492
unique_str2 = 'unique str ' + osutils.rand_chars(20)
493
key = self.module.StaticTuple(unique_str1, unique_str2)
494
self.assertFalse(key in self.module._interned_tuples)
495
key2 = self.module.StaticTuple(unique_str1, unique_str2)
496
self.assertEqual(key, key2)
497
self.assertIsNot(key, key2)
499
self.assertIs(key, key3)
500
self.assertTrue(key in self.module._interned_tuples)
501
self.assertEqual(key, self.module._interned_tuples[key])
503
self.assertIs(key, key2)
505
def test__c_intern_handles_refcount(self):
506
if self.module is _static_tuple_py:
507
return # Not applicable
508
unique_str1 = 'unique str ' + osutils.rand_chars(20)
509
unique_str2 = 'unique str ' + osutils.rand_chars(20)
510
key = self.module.StaticTuple(unique_str1, unique_str2)
511
self.assertRefcount(1, key)
512
self.assertFalse(key in self.module._interned_tuples)
513
self.assertFalse(key._is_interned())
514
key2 = self.module.StaticTuple(unique_str1, unique_str2)
515
self.assertRefcount(1, key)
516
self.assertRefcount(1, key2)
517
self.assertEqual(key, key2)
518
self.assertIsNot(key, key2)
521
self.assertIs(key, key3)
522
self.assertTrue(key in self.module._interned_tuples)
523
self.assertEqual(key, self.module._interned_tuples[key])
524
# key and key3, but we 'hide' the one in _interned_tuples
525
self.assertRefcount(2, key)
527
self.assertRefcount(1, key)
528
self.assertTrue(key._is_interned())
529
self.assertRefcount(1, key2)
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)
538
self.assertRefcount(1, key)
540
def test__c_keys_are_not_immortal(self):
541
if self.module is _static_tuple_py:
542
return # Not applicable
543
unique_str1 = 'unique str ' + osutils.rand_chars(20)
544
unique_str2 = 'unique str ' + osutils.rand_chars(20)
545
key = self.module.StaticTuple(unique_str1, unique_str2)
546
self.assertFalse(key in self.module._interned_tuples)
547
self.assertRefcount(1, key)
549
self.assertRefcount(1, key)
550
self.assertTrue(key in self.module._interned_tuples)
551
self.assertTrue(key._is_interned())
553
# Create a new entry, which would point to the same location
554
key = self.module.StaticTuple(unique_str1, unique_str2)
555
self.assertRefcount(1, key)
556
# This old entry in _interned_tuples should be gone
557
self.assertFalse(key in self.module._interned_tuples)
558
self.assertFalse(key._is_interned())
560
def test__c_has_C_API(self):
561
if self.module is _static_tuple_py:
563
self.assertIsNot(None, self.module._C_API)
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)
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)
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)
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)
586
def test_from_sequence_not_sequence(self):
587
self.assertRaises(TypeError,
588
self.module.StaticTuple.from_sequence, object())
589
self.assertRaises(TypeError,
590
self.module.StaticTuple.from_sequence, 10)
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')
598
def test_from_sequence_iterable(self):
599
st = self.module.StaticTuple.from_sequence(iter(['foo', 'bar']))
600
self.assertIsInstance(st, self.module.StaticTuple)
601
self.assertEqual(('foo', 'bar'), st)
603
def test_from_sequence_generator(self):
604
def generate_tuple():
607
st = self.module.StaticTuple.from_sequence(generate_tuple())
608
self.assertIsInstance(st, self.module.StaticTuple)
609
self.assertEqual(('foo', 'bar'), st)
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)
617
def test_pickle_empty(self):
618
st = self.module.StaticTuple()
619
pickled = cPickle.dumps(st)
620
unpickled = cPickle.loads(pickled)
621
self.assertIs(st, unpickled)
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)
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:
633
if compiled_static_tuple_feature.available():
634
# We will be using the C version
636
self.assertIs(static_tuple.StaticTuple,
637
self.module.StaticTuple)
640
class TestEnsureStaticTuple(tests.TestCase):
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)
647
def test_is_tuple(self):
649
st = static_tuple.expect_static_tuple(t)
650
self.assertIsInstance(st, static_tuple.StaticTuple)
651
self.assertEqual(t, st)
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)
659
def test_flagged_is_tuple(self):
660
debug.debug_flags.add('static_tuple')
662
self.assertRaises(TypeError, static_tuple.expect_static_tuple, t)