1
# Copyright (C) 2009, 2010, 2011 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."""
20
import cPickle as pickle
33
from breezy.tests import (
38
def load_tests(loader, standard_tests, pattern):
39
"""Parameterize tests for all versions of groupcompress."""
40
global compiled_static_tuple_feature
41
suite, compiled_static_tuple_feature = tests.permute_tests_for_extension(
42
standard_tests, loader, 'breezy._static_tuple_py',
43
'breezy._static_tuple_c')
47
class TestStaticTuple(tests.TestCase):
49
def assertRefcount(self, count, obj):
50
"""Assert that the refcount for obj is what we expect.
52
Note that this automatically adjusts for the fact that calling
53
assertRefcount actually creates a new pointer, as does calling
54
sys.getrefcount. So pass the expected value *before* the call.
56
# I don't understand why it is getrefcount()-3 here, but it seems to be
57
# correct. If I check in the calling function, with:
58
# self.assertEqual(count, sys.getrefcount(obj)-1)
59
# Then it works fine. Something about passing it to assertRefcount is
60
# actually double-incrementing (and decrementing) the refcount
61
self.assertEqual(count, sys.getrefcount(obj) - 3)
63
def test_create(self):
64
k = self.module.StaticTuple('foo')
65
k = self.module.StaticTuple('foo', 'bar')
67
def test_create_bad_args(self):
68
args_256 = ['a'] * 256
70
self.assertRaises(TypeError, self.module.StaticTuple, *args_256)
71
args_300 = ['a'] * 300
72
self.assertRaises(TypeError, self.module.StaticTuple, *args_300)
74
self.assertRaises(TypeError, self.module.StaticTuple, object())
76
def test_concat(self):
77
st1 = self.module.StaticTuple('foo')
78
st2 = self.module.StaticTuple('bar')
79
st3 = self.module.StaticTuple('foo', 'bar')
81
self.assertEqual(st3, st4)
82
self.assertIsInstance(st4, self.module.StaticTuple)
84
def test_concat_with_tuple(self):
85
st1 = self.module.StaticTuple('foo')
87
st3 = self.module.StaticTuple('foo', 'bar')
88
st4 = self.module.StaticTuple('bar', 'foo')
91
self.assertEqual(st3, st5)
92
self.assertIsInstance(st5, self.module.StaticTuple)
93
self.assertEqual(st4, st6)
94
if self.module is _static_tuple_py:
95
# _static_tuple_py has StaticTuple(tuple), so tuple thinks it
96
# already knows how to concatenate, as such we can't "inject" our
97
# own concatenation...
98
self.assertIsInstance(st6, tuple)
100
self.assertIsInstance(st6, self.module.StaticTuple)
102
def test_concat_with_bad_tuple(self):
103
st1 = self.module.StaticTuple('foo')
105
# Using st1.__add__ doesn't give the same results as doing the '+' form
106
self.assertRaises(TypeError, lambda: st1 + t2)
108
def test_concat_with_non_tuple(self):
109
st1 = self.module.StaticTuple('foo')
110
self.assertRaises(TypeError, lambda: st1 + 10)
112
def test_as_tuple(self):
113
k = self.module.StaticTuple('foo')
115
self.assertEqual(('foo',), t)
116
self.assertIsInstance(t, tuple)
117
self.assertFalse(isinstance(t, self.module.StaticTuple))
118
k = self.module.StaticTuple('foo', 'bar')
120
self.assertEqual(('foo', 'bar'), t)
121
k2 = self.module.StaticTuple(1, k)
123
self.assertIsInstance(t, tuple)
124
# For pickling to work, we need to keep the sub-items as StaticTuple so
125
# that it knows that they also need to be converted.
126
self.assertIsInstance(t[1], self.module.StaticTuple)
127
self.assertEqual((1, ('foo', 'bar')), t)
129
def test_as_tuples(self):
130
k1 = self.module.StaticTuple('foo', 'bar')
131
t = static_tuple.as_tuples(k1)
132
self.assertIsInstance(t, tuple)
133
self.assertEqual(('foo', 'bar'), t)
134
k2 = self.module.StaticTuple(1, k1)
135
t = static_tuple.as_tuples(k2)
136
self.assertIsInstance(t, tuple)
137
self.assertIsInstance(t[1], tuple)
138
self.assertEqual((1, ('foo', 'bar')), t)
140
t = static_tuple.as_tuples(mixed)
141
self.assertIsInstance(t, tuple)
142
self.assertIsInstance(t[1], tuple)
143
self.assertEqual((1, ('foo', 'bar')), t)
146
k = self.module.StaticTuple()
147
self.assertEqual(0, len(k))
148
k = self.module.StaticTuple('foo')
149
self.assertEqual(1, len(k))
150
k = self.module.StaticTuple('foo', 'bar')
151
self.assertEqual(2, len(k))
152
k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'b')
153
self.assertEqual(7, len(k))
155
k = self.module.StaticTuple(*args)
156
self.assertEqual(255, len(k))
158
def test_hold_other_static_tuples(self):
159
k = self.module.StaticTuple('foo', 'bar')
160
k2 = self.module.StaticTuple(k, k)
161
self.assertEqual(2, len(k2))
162
self.assertIs(k, k2[0])
163
self.assertIs(k, k2[1])
165
def test_getitem(self):
166
k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'z')
167
self.assertEqual('foo', k[0])
168
self.assertEqual('foo', k[0])
169
self.assertEqual('foo', k[0])
170
self.assertEqual('z', k[6])
171
self.assertEqual('z', k[-1])
172
self.assertRaises(IndexError, k.__getitem__, 7)
173
self.assertRaises(IndexError, k.__getitem__, 256 + 7)
174
self.assertRaises(IndexError, k.__getitem__, 12024)
175
# Python's [] resolver handles the negative arguments, so we can't
176
# really test StaticTuple_item() with negative values.
177
self.assertRaises(TypeError, k.__getitem__, 'not-an-int')
178
self.assertRaises(TypeError, k.__getitem__, '5')
180
def test_refcount(self):
182
num_refs = sys.getrefcount(f) - 1 # sys.getrefcount() adds one
183
k = self.module.StaticTuple(f)
184
self.assertRefcount(num_refs + 1, f)
186
self.assertRefcount(num_refs + 2, f)
188
self.assertRefcount(num_refs + 2, f)
190
self.assertRefcount(num_refs + 3, f)
192
self.assertRefcount(num_refs + 1, f)
194
self.assertRefcount(num_refs, f)
196
def test__repr__(self):
197
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
198
self.assertEqual("StaticTuple('foo', 'bar', 'baz', 'bing')", repr(k))
200
def assertCompareEqual(self, k1, k2):
201
self.assertTrue(k1 == k2)
202
self.assertTrue(k1 <= k2)
203
self.assertTrue(k1 >= k2)
204
self.assertFalse(k1 != k2)
205
self.assertFalse(k1 < k2)
206
self.assertFalse(k1 > k2)
208
def test_holds_None(self):
209
k1 = self.module.StaticTuple(None)
210
# You cannot subclass None anyway
212
def test_holds_int(self):
213
k1 = self.module.StaticTuple(1)
217
# But not a subclass, because subint could introduce refcycles
218
self.assertRaises(TypeError, self.module.StaticTuple, subint(2))
220
def test_holds_float(self):
221
k1 = self.module.StaticTuple(1.2)
223
class subfloat(float):
225
self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
227
def test_holds_bytes(self):
228
k1 = self.module.StaticTuple(b'astring')
232
self.assertRaises(TypeError, self.module.StaticTuple, substr(b'a'))
234
def test_holds_unicode(self):
235
k1 = self.module.StaticTuple(u'\xb5')
237
class subunicode(str):
239
self.assertRaises(TypeError, self.module.StaticTuple,
242
def test_hold_bool(self):
243
k1 = self.module.StaticTuple(True)
244
k2 = self.module.StaticTuple(False)
245
# Cannot subclass bool
247
def test_compare_same_obj(self):
248
k1 = self.module.StaticTuple('foo', 'bar')
249
self.assertCompareEqual(k1, k1)
250
k2 = self.module.StaticTuple(k1, k1)
251
self.assertCompareEqual(k2, k2)
252
k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
254
self.assertCompareEqual(k3, k3)
256
def test_compare_equivalent_obj(self):
257
k1 = self.module.StaticTuple('foo', 'bar')
258
k2 = self.module.StaticTuple('foo', 'bar')
259
self.assertCompareEqual(k1, k2)
260
k3 = self.module.StaticTuple(k1, k2)
261
k4 = self.module.StaticTuple(k2, k1)
262
self.assertCompareEqual(k1, k2)
263
k5 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
265
k6 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
267
self.assertCompareEqual(k5, k6)
268
k7 = self.module.StaticTuple(None)
269
k8 = self.module.StaticTuple(None)
270
self.assertCompareEqual(k7, k8)
272
def test_compare_similar_obj(self):
273
k1 = self.module.StaticTuple('foo' + ' bar', 'bar' + ' baz')
274
k2 = self.module.StaticTuple('fo' + 'o bar', 'ba' + 'r baz')
275
self.assertCompareEqual(k1, k2)
276
k3 = self.module.StaticTuple('foo ' + 'bar', 'bar ' + 'baz')
277
k4 = self.module.StaticTuple('f' + 'oo bar', 'b' + 'ar baz')
278
k5 = self.module.StaticTuple(k1, k2)
279
k6 = self.module.StaticTuple(k3, k4)
280
self.assertCompareEqual(k5, k6)
282
def check_strict_compare(self, k1, k2, mismatched_types):
283
"""True if on Python 3 and stricter comparison semantics are used."""
285
for op in ("ge", "gt", "le", "lt"):
286
self.assertRaises(TypeError, getattr(operator, op), k1, k2)
290
def assertCompareDifferent(self, k_small, k_big, mismatched_types=False):
291
self.assertFalse(k_small == k_big)
292
self.assertTrue(k_small != k_big)
293
if not self.check_strict_compare(k_small, k_big, mismatched_types):
294
self.assertFalse(k_small >= k_big)
295
self.assertFalse(k_small > k_big)
296
self.assertTrue(k_small <= k_big)
297
self.assertTrue(k_small < k_big)
299
def assertCompareNoRelation(self, k1, k2, mismatched_types=False):
300
"""Run the comparison operators, make sure they do something.
302
However, we don't actually care what comes first or second. This is
303
stuff like cross-class comparisons. We don't want to segfault/raise an
304
exception, but we don't care about the sort order.
306
self.assertFalse(k1 == k2)
307
self.assertTrue(k1 != k2)
308
if not self.check_strict_compare(k1, k2, mismatched_types):
309
# Do the comparison, but we don't care about the result
315
def test_compare_vs_none(self):
316
k1 = self.module.StaticTuple('baz', 'bing')
317
self.assertCompareDifferent(None, k1, mismatched_types=True)
319
def test_compare_cross_class(self):
320
k1 = self.module.StaticTuple('baz', 'bing')
321
self.assertCompareNoRelation(10, k1, mismatched_types=True)
322
self.assertCompareNoRelation('baz', k1, mismatched_types=True)
324
def test_compare_all_different_same_width(self):
325
k1 = self.module.StaticTuple('baz', 'bing')
326
k2 = self.module.StaticTuple('foo', 'bar')
327
self.assertCompareDifferent(k1, k2)
328
k3 = self.module.StaticTuple(k1, k2)
329
k4 = self.module.StaticTuple(k2, k1)
330
self.assertCompareDifferent(k3, k4)
331
k5 = self.module.StaticTuple(1)
332
k6 = self.module.StaticTuple(2)
333
self.assertCompareDifferent(k5, k6)
334
k7 = self.module.StaticTuple(1.2)
335
k8 = self.module.StaticTuple(2.4)
336
self.assertCompareDifferent(k7, k8)
337
k9 = self.module.StaticTuple(u's\xb5')
338
k10 = self.module.StaticTuple(u's\xe5')
339
self.assertCompareDifferent(k9, k10)
341
def test_compare_some_different(self):
342
k1 = self.module.StaticTuple('foo', 'bar')
343
k2 = self.module.StaticTuple('foo', 'zzz')
344
self.assertCompareDifferent(k1, k2)
345
k3 = self.module.StaticTuple(k1, k1)
346
k4 = self.module.StaticTuple(k1, k2)
347
self.assertCompareDifferent(k3, k4)
348
k5 = self.module.StaticTuple('foo', None)
349
self.assertCompareDifferent(k5, k1, mismatched_types=True)
350
self.assertCompareDifferent(k5, k2, mismatched_types=True)
352
def test_compare_diff_width(self):
353
k1 = self.module.StaticTuple('foo')
354
k2 = self.module.StaticTuple('foo', 'bar')
355
self.assertCompareDifferent(k1, k2)
356
k3 = self.module.StaticTuple(k1)
357
k4 = self.module.StaticTuple(k1, k2)
358
self.assertCompareDifferent(k3, k4)
360
def test_compare_different_types(self):
361
k1 = self.module.StaticTuple('foo', 'bar')
362
k2 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
364
self.assertCompareNoRelation(k1, k2, mismatched_types=True)
365
k3 = self.module.StaticTuple('foo')
366
self.assertCompareDifferent(k3, k1)
367
k4 = self.module.StaticTuple(None)
368
self.assertCompareDifferent(k4, k1, mismatched_types=True)
369
k5 = self.module.StaticTuple(1)
370
self.assertCompareNoRelation(k1, k5, mismatched_types=True)
372
def test_compare_to_tuples(self):
373
k1 = self.module.StaticTuple('foo')
374
self.assertCompareEqual(k1, ('foo',))
375
self.assertCompareEqual(('foo',), k1)
376
self.assertCompareDifferent(k1, ('foo', 'bar'))
377
self.assertCompareDifferent(k1, ('foo', 10))
379
k2 = self.module.StaticTuple('foo', 'bar')
380
self.assertCompareEqual(k2, ('foo', 'bar'))
381
self.assertCompareEqual(('foo', 'bar'), k2)
382
self.assertCompareDifferent(k2, ('foo', 'zzz'))
383
self.assertCompareDifferent(('foo',), k2)
384
self.assertCompareDifferent(('foo', 'aaa'), k2)
385
self.assertCompareDifferent(('baz', 'bing'), k2)
386
self.assertCompareDifferent(('foo', 10), k2, mismatched_types=True)
388
k3 = self.module.StaticTuple(k1, k2)
389
self.assertCompareEqual(k3, (('foo',), ('foo', 'bar')))
390
self.assertCompareEqual((('foo',), ('foo', 'bar')), k3)
391
self.assertCompareEqual(k3, (k1, ('foo', 'bar')))
392
self.assertCompareEqual((k1, ('foo', 'bar')), k3)
394
def test_compare_mixed_depths(self):
395
stuple = self.module.StaticTuple
396
k1 = stuple(stuple('a',), stuple('b',))
397
k2 = stuple(stuple(stuple('c',), stuple('d',)),
399
# This requires comparing a StaticTuple to a 'string', and then
400
# interpreting that value in the next higher StaticTuple. This used to
401
# generate a PyErr_BadIternalCall. We now fall back to *something*.
402
self.assertCompareNoRelation(k1, k2, mismatched_types=True)
405
k = self.module.StaticTuple('foo')
406
self.assertEqual(hash(k), hash(('foo',)))
407
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
408
as_tuple = ('foo', 'bar', 'baz', 'bing')
409
self.assertEqual(hash(k), hash(as_tuple))
411
# Because k == , it replaces the slot, rather than having both
412
# present in the dict.
413
self.assertEqual('foo', x[as_tuple])
415
self.assertEqual({as_tuple: 'bar'}, x)
417
k2 = self.module.StaticTuple(k)
418
as_tuple2 = (('foo', 'bar', 'baz', 'bing'),)
419
self.assertEqual(hash(k2), hash(as_tuple2))
421
k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
423
as_tuple3 = ('foo', 1, None, u'\xb5', 1.2, 2**65, True, k)
424
self.assertEqual(hash(as_tuple3), hash(k3))
426
def test_slice(self):
427
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
428
self.assertEqual(('foo', 'bar'), k[:2])
429
self.assertEqual(('baz',), k[2:-1])
430
self.assertEqual(('foo', 'baz',), k[::2])
431
self.assertRaises(TypeError, k.__getitem__, 'not_slice')
433
def test_referents(self):
434
# We implement tp_traverse so that things like 'meliae' can measure the
435
# amount of referenced memory. Unfortunately gc.get_referents() first
436
# checks the IS_GC flag before it traverses anything. We could write a
437
# helper func, but that won't work for the generic implementation...
438
self.requireFeature(features.meliae)
439
from meliae import scanner
440
strs = ['foo', 'bar', 'baz', 'bing']
441
k = self.module.StaticTuple(*strs)
442
if self.module is _static_tuple_py:
443
refs = strs + [self.module.StaticTuple]
446
self.assertEqual(sorted(refs), sorted(scanner.get_referents(k)))
448
def test_nested_referents(self):
449
self.requireFeature(features.meliae)
450
from meliae import scanner
451
strs = ['foo', 'bar', 'baz', 'bing']
452
k1 = self.module.StaticTuple(*strs[:2])
453
k2 = self.module.StaticTuple(*strs[2:])
454
k3 = self.module.StaticTuple(k1, k2)
456
if self.module is _static_tuple_py:
457
refs.append(self.module.StaticTuple)
458
self.assertEqual(sorted(refs),
459
sorted(scanner.get_referents(k3)))
461
def test_empty_is_singleton(self):
462
key = self.module.StaticTuple()
463
self.assertIs(key, self.module._empty_tuple)
465
def test_intern(self):
466
unique_str1 = 'unique str ' + osutils.rand_chars(20)
467
unique_str2 = 'unique str ' + osutils.rand_chars(20)
468
key = self.module.StaticTuple(unique_str1, unique_str2)
469
self.assertFalse(key in self.module._interned_tuples)
470
key2 = self.module.StaticTuple(unique_str1, unique_str2)
471
self.assertEqual(key, key2)
472
self.assertIsNot(key, key2)
474
self.assertIs(key, key3)
475
self.assertTrue(key in self.module._interned_tuples)
476
self.assertEqual(key, self.module._interned_tuples[key])
478
self.assertIs(key, key2)
480
def test__c_intern_handles_refcount(self):
481
if self.module is _static_tuple_py:
482
return # Not applicable
483
unique_str1 = 'unique str ' + osutils.rand_chars(20)
484
unique_str2 = 'unique str ' + osutils.rand_chars(20)
485
key = self.module.StaticTuple(unique_str1, unique_str2)
486
self.assertRefcount(1, key)
487
self.assertFalse(key in self.module._interned_tuples)
488
self.assertFalse(key._is_interned())
489
key2 = self.module.StaticTuple(unique_str1, unique_str2)
490
self.assertRefcount(1, key)
491
self.assertRefcount(1, key2)
492
self.assertEqual(key, key2)
493
self.assertIsNot(key, key2)
496
self.assertIs(key, key3)
497
self.assertTrue(key in self.module._interned_tuples)
498
self.assertEqual(key, self.module._interned_tuples[key])
499
# key and key3, but we 'hide' the one in _interned_tuples
500
self.assertRefcount(2, key)
502
self.assertRefcount(1, key)
503
self.assertTrue(key._is_interned())
504
self.assertRefcount(1, key2)
506
# key3 now points to key as well, and *not* to key2
507
self.assertRefcount(2, key)
508
self.assertRefcount(1, key2)
509
self.assertIs(key, key3)
510
self.assertIsNot(key3, key2)
513
self.assertRefcount(1, key)
515
def test__c_keys_are_not_immortal(self):
516
if self.module is _static_tuple_py:
517
return # Not applicable
518
unique_str1 = 'unique str ' + osutils.rand_chars(20)
519
unique_str2 = 'unique str ' + osutils.rand_chars(20)
520
key = self.module.StaticTuple(unique_str1, unique_str2)
521
self.assertFalse(key in self.module._interned_tuples)
522
self.assertRefcount(1, key)
524
self.assertRefcount(1, key)
525
self.assertTrue(key in self.module._interned_tuples)
526
self.assertTrue(key._is_interned())
528
# Create a new entry, which would point to the same location
529
key = self.module.StaticTuple(unique_str1, unique_str2)
530
self.assertRefcount(1, key)
531
# This old entry in _interned_tuples should be gone
532
self.assertFalse(key in self.module._interned_tuples)
533
self.assertFalse(key._is_interned())
535
def test__c_has_C_API(self):
536
if self.module is _static_tuple_py:
538
self.assertIsNot(None, self.module._C_API)
540
def test_from_sequence_tuple(self):
541
st = self.module.StaticTuple.from_sequence(('foo', 'bar'))
542
self.assertIsInstance(st, self.module.StaticTuple)
543
self.assertEqual(('foo', 'bar'), st)
545
def test_from_sequence_str(self):
546
st = self.module.StaticTuple.from_sequence('foo')
547
self.assertIsInstance(st, self.module.StaticTuple)
548
self.assertEqual(('f', 'o', 'o'), st)
550
def test_from_sequence_list(self):
551
st = self.module.StaticTuple.from_sequence(['foo', 'bar'])
552
self.assertIsInstance(st, self.module.StaticTuple)
553
self.assertEqual(('foo', 'bar'), st)
555
def test_from_sequence_static_tuple(self):
556
st = self.module.StaticTuple('foo', 'bar')
557
st2 = self.module.StaticTuple.from_sequence(st)
558
# If the source is a StaticTuple already, we return the exact object
559
self.assertIs(st, st2)
561
def test_from_sequence_not_sequence(self):
562
self.assertRaises(TypeError,
563
self.module.StaticTuple.from_sequence, object())
564
self.assertRaises(TypeError,
565
self.module.StaticTuple.from_sequence, 10)
567
def test_from_sequence_incorrect_args(self):
568
self.assertRaises(TypeError,
569
self.module.StaticTuple.from_sequence, object(), 'a')
570
self.assertRaises(TypeError,
571
self.module.StaticTuple.from_sequence, foo='a')
573
def test_from_sequence_iterable(self):
574
st = self.module.StaticTuple.from_sequence(iter(['foo', 'bar']))
575
self.assertIsInstance(st, self.module.StaticTuple)
576
self.assertEqual(('foo', 'bar'), st)
578
def test_from_sequence_generator(self):
579
def generate_tuple():
582
st = self.module.StaticTuple.from_sequence(generate_tuple())
583
self.assertIsInstance(st, self.module.StaticTuple)
584
self.assertEqual(('foo', 'bar'), st)
586
def test_pickle(self):
587
st = self.module.StaticTuple('foo', 'bar')
588
pickled = pickle.dumps(st)
589
unpickled = pickle.loads(pickled)
590
self.assertEqual(unpickled, st)
592
def test_pickle_empty(self):
593
st = self.module.StaticTuple()
594
pickled = pickle.dumps(st)
595
unpickled = pickle.loads(pickled)
596
self.assertIs(st, unpickled)
598
def test_pickle_nested(self):
599
st = self.module.StaticTuple('foo', self.module.StaticTuple('bar'))
600
pickled = pickle.dumps(st)
601
unpickled = pickle.loads(pickled)
602
self.assertEqual(unpickled, st)
604
def test_static_tuple_thunk(self):
605
# Make sure the right implementation is available from
606
# breezy.static_tuple.StaticTuple.
607
if self.module is _static_tuple_py:
608
if compiled_static_tuple_feature.available():
609
# We will be using the C version
611
self.assertIs(static_tuple.StaticTuple,
612
self.module.StaticTuple)
615
class TestEnsureStaticTuple(tests.TestCase):
617
def test_is_static_tuple(self):
618
st = static_tuple.StaticTuple('foo')
619
st2 = static_tuple.expect_static_tuple(st)
620
self.assertIs(st, st2)
622
def test_is_tuple(self):
624
st = static_tuple.expect_static_tuple(t)
625
self.assertIsInstance(st, static_tuple.StaticTuple)
626
self.assertEqual(t, st)
628
def test_flagged_is_static_tuple(self):
629
debug.debug_flags.add('static_tuple')
630
st = static_tuple.StaticTuple('foo')
631
st2 = static_tuple.expect_static_tuple(st)
632
self.assertIs(st, st2)
634
def test_flagged_is_tuple(self):
635
debug.debug_flags.add('static_tuple')
637
self.assertRaises(TypeError, static_tuple.expect_static_tuple, t)