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.sixish import (
37
from breezy.tests import (
42
def load_tests(loader, standard_tests, pattern):
43
"""Parameterize tests for all versions of groupcompress."""
44
global compiled_static_tuple_feature
45
suite, compiled_static_tuple_feature = tests.permute_tests_for_extension(
46
standard_tests, loader, 'breezy._static_tuple_py',
47
'breezy._static_tuple_c')
51
class TestStaticTuple(tests.TestCase):
53
def assertRefcount(self, count, obj):
54
"""Assert that the refcount for obj is what we expect.
56
Note that this automatically adjusts for the fact that calling
57
assertRefcount actually creates a new pointer, as does calling
58
sys.getrefcount. So pass the expected value *before* the call.
60
# I don't understand why it is getrefcount()-3 here, but it seems to be
61
# correct. If I check in the calling function, with:
62
# self.assertEqual(count, sys.getrefcount(obj)-1)
63
# Then it works fine. Something about passing it to assertRefcount is
64
# actually double-incrementing (and decrementing) the refcount
65
self.assertEqual(count, sys.getrefcount(obj)-3)
67
def test_create(self):
68
k = self.module.StaticTuple('foo')
69
k = self.module.StaticTuple('foo', 'bar')
71
def test_create_bad_args(self):
74
self.assertRaises(TypeError, self.module.StaticTuple, *args_256)
76
self.assertRaises(TypeError, self.module.StaticTuple, *args_300)
78
self.assertRaises(TypeError, self.module.StaticTuple, object())
80
def test_concat(self):
81
st1 = self.module.StaticTuple('foo')
82
st2 = self.module.StaticTuple('bar')
83
st3 = self.module.StaticTuple('foo', 'bar')
85
self.assertEqual(st3, st4)
86
self.assertIsInstance(st4, self.module.StaticTuple)
88
def test_concat_with_tuple(self):
89
st1 = self.module.StaticTuple('foo')
91
st3 = self.module.StaticTuple('foo', 'bar')
92
st4 = self.module.StaticTuple('bar', 'foo')
95
self.assertEqual(st3, st5)
96
self.assertIsInstance(st5, self.module.StaticTuple)
97
self.assertEqual(st4, st6)
98
if self.module is _static_tuple_py:
99
# _static_tuple_py has StaticTuple(tuple), so tuple thinks it
100
# already knows how to concatenate, as such we can't "inject" our
101
# own concatenation...
102
self.assertIsInstance(st6, tuple)
104
self.assertIsInstance(st6, self.module.StaticTuple)
106
def test_concat_with_bad_tuple(self):
107
st1 = self.module.StaticTuple('foo')
109
# Using st1.__add__ doesn't give the same results as doing the '+' form
110
self.assertRaises(TypeError, lambda: st1 + t2)
112
def test_concat_with_non_tuple(self):
113
st1 = self.module.StaticTuple('foo')
114
self.assertRaises(TypeError, lambda: st1 + 10)
116
def test_as_tuple(self):
117
k = self.module.StaticTuple('foo')
119
self.assertEqual(('foo',), t)
120
self.assertIsInstance(t, tuple)
121
self.assertFalse(isinstance(t, self.module.StaticTuple))
122
k = self.module.StaticTuple('foo', 'bar')
124
self.assertEqual(('foo', 'bar'), t)
125
k2 = self.module.StaticTuple(1, k)
127
self.assertIsInstance(t, tuple)
128
# For pickling to work, we need to keep the sub-items as StaticTuple so
129
# that it knows that they also need to be converted.
130
self.assertIsInstance(t[1], self.module.StaticTuple)
131
self.assertEqual((1, ('foo', 'bar')), t)
133
def test_as_tuples(self):
134
k1 = self.module.StaticTuple('foo', 'bar')
135
t = static_tuple.as_tuples(k1)
136
self.assertIsInstance(t, tuple)
137
self.assertEqual(('foo', 'bar'), t)
138
k2 = self.module.StaticTuple(1, k1)
139
t = static_tuple.as_tuples(k2)
140
self.assertIsInstance(t, tuple)
141
self.assertIsInstance(t[1], tuple)
142
self.assertEqual((1, ('foo', 'bar')), t)
144
t = static_tuple.as_tuples(mixed)
145
self.assertIsInstance(t, tuple)
146
self.assertIsInstance(t[1], tuple)
147
self.assertEqual((1, ('foo', 'bar')), t)
150
k = self.module.StaticTuple()
151
self.assertEqual(0, len(k))
152
k = self.module.StaticTuple('foo')
153
self.assertEqual(1, len(k))
154
k = self.module.StaticTuple('foo', 'bar')
155
self.assertEqual(2, len(k))
156
k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'b')
157
self.assertEqual(7, len(k))
159
k = self.module.StaticTuple(*args)
160
self.assertEqual(255, len(k))
162
def test_hold_other_static_tuples(self):
163
k = self.module.StaticTuple('foo', 'bar')
164
k2 = self.module.StaticTuple(k, k)
165
self.assertEqual(2, len(k2))
166
self.assertIs(k, k2[0])
167
self.assertIs(k, k2[1])
169
def test_getitem(self):
170
k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'z')
171
self.assertEqual('foo', k[0])
172
self.assertEqual('foo', k[0])
173
self.assertEqual('foo', k[0])
174
self.assertEqual('z', k[6])
175
self.assertEqual('z', k[-1])
176
self.assertRaises(IndexError, k.__getitem__, 7)
177
self.assertRaises(IndexError, k.__getitem__, 256+7)
178
self.assertRaises(IndexError, k.__getitem__, 12024)
179
# Python's [] resolver handles the negative arguments, so we can't
180
# really test StaticTuple_item() with negative values.
181
self.assertRaises(TypeError, k.__getitem__, 'not-an-int')
182
self.assertRaises(TypeError, k.__getitem__, '5')
184
def test_refcount(self):
186
num_refs = sys.getrefcount(f) - 1 #sys.getrefcount() adds one
187
k = self.module.StaticTuple(f)
188
self.assertRefcount(num_refs + 1, f)
190
self.assertRefcount(num_refs + 2, f)
192
self.assertRefcount(num_refs + 2, f)
194
self.assertRefcount(num_refs + 3, f)
196
self.assertRefcount(num_refs + 1, f)
198
self.assertRefcount(num_refs, f)
200
def test__repr__(self):
201
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
202
self.assertEqual("StaticTuple('foo', 'bar', 'baz', 'bing')", repr(k))
204
def assertCompareEqual(self, k1, k2):
205
self.assertTrue(k1 == k2)
206
self.assertTrue(k1 <= k2)
207
self.assertTrue(k1 >= k2)
208
self.assertFalse(k1 != k2)
209
self.assertFalse(k1 < k2)
210
self.assertFalse(k1 > k2)
212
def test_holds_None(self):
213
k1 = self.module.StaticTuple(None)
214
# You cannot subclass None anyway
216
def test_holds_int(self):
217
k1 = self.module.StaticTuple(1)
220
# But not a subclass, because subint could introduce refcycles
221
self.assertRaises(TypeError, self.module.StaticTuple, subint(2))
223
def test_holds_long(self):
225
self.skipTest("No long type on Python 3")
226
k1 = self.module.StaticTuple(2**65)
230
self.assertRaises(TypeError, self.module.StaticTuple, sublong(1))
232
def test_holds_float(self):
233
k1 = self.module.StaticTuple(1.2)
234
class subfloat(float):
236
self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
238
def test_holds_bytes(self):
239
k1 = self.module.StaticTuple(b'astring')
242
self.assertRaises(TypeError, self.module.StaticTuple, substr(b'a'))
244
def test_holds_unicode(self):
245
k1 = self.module.StaticTuple(u'\xb5')
246
class subunicode(text_type):
248
self.assertRaises(TypeError, self.module.StaticTuple,
251
def test_hold_bool(self):
252
k1 = self.module.StaticTuple(True)
253
k2 = self.module.StaticTuple(False)
254
# Cannot subclass bool
256
def test_compare_same_obj(self):
257
k1 = self.module.StaticTuple('foo', 'bar')
258
self.assertCompareEqual(k1, k1)
259
k2 = self.module.StaticTuple(k1, k1)
260
self.assertCompareEqual(k2, k2)
261
k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
263
self.assertCompareEqual(k3, k3)
265
def test_compare_equivalent_obj(self):
266
k1 = self.module.StaticTuple('foo', 'bar')
267
k2 = self.module.StaticTuple('foo', 'bar')
268
self.assertCompareEqual(k1, k2)
269
k3 = self.module.StaticTuple(k1, k2)
270
k4 = self.module.StaticTuple(k2, k1)
271
self.assertCompareEqual(k1, k2)
272
k5 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
274
k6 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
276
self.assertCompareEqual(k5, k6)
277
k7 = self.module.StaticTuple(None)
278
k8 = self.module.StaticTuple(None)
279
self.assertCompareEqual(k7, k8)
281
def test_compare_similar_obj(self):
282
k1 = self.module.StaticTuple('foo' + ' bar', 'bar' + ' baz')
283
k2 = self.module.StaticTuple('fo' + 'o bar', 'ba' + 'r baz')
284
self.assertCompareEqual(k1, k2)
285
k3 = self.module.StaticTuple('foo ' + 'bar', 'bar ' + 'baz')
286
k4 = self.module.StaticTuple('f' + 'oo bar', 'b' + 'ar baz')
287
k5 = self.module.StaticTuple(k1, k2)
288
k6 = self.module.StaticTuple(k3, k4)
289
self.assertCompareEqual(k5, k6)
291
def check_strict_compare(self, k1, k2, mismatched_types):
292
"""True if on Python 3 and stricter comparison semantics are used."""
293
if PY3 and mismatched_types:
294
for op in ("ge", "gt", "le", "lt"):
295
self.assertRaises(TypeError, getattr(operator, op), k1, k2)
299
def assertCompareDifferent(self, k_small, k_big, mismatched_types=False):
300
self.assertFalse(k_small == k_big)
301
self.assertTrue(k_small != k_big)
302
if not self.check_strict_compare(k_small, k_big, mismatched_types):
303
self.assertFalse(k_small >= k_big)
304
self.assertFalse(k_small > k_big)
305
self.assertTrue(k_small <= k_big)
306
self.assertTrue(k_small < k_big)
308
def assertCompareNoRelation(self, k1, k2, mismatched_types=False):
309
"""Run the comparison operators, make sure they do something.
311
However, we don't actually care what comes first or second. This is
312
stuff like cross-class comparisons. We don't want to segfault/raise an
313
exception, but we don't care about the sort order.
315
self.assertFalse(k1 == k2)
316
self.assertTrue(k1 != k2)
317
if not self.check_strict_compare(k1, k2, mismatched_types):
318
# Do the comparison, but we don't care about the result
324
def test_compare_vs_none(self):
325
k1 = self.module.StaticTuple('baz', 'bing')
326
self.assertCompareDifferent(None, k1, mismatched_types=True)
328
def test_compare_cross_class(self):
329
k1 = self.module.StaticTuple('baz', 'bing')
330
self.assertCompareNoRelation(10, k1, mismatched_types=True)
331
self.assertCompareNoRelation('baz', k1, mismatched_types=True)
333
def test_compare_all_different_same_width(self):
334
k1 = self.module.StaticTuple('baz', 'bing')
335
k2 = self.module.StaticTuple('foo', 'bar')
336
self.assertCompareDifferent(k1, k2)
337
k3 = self.module.StaticTuple(k1, k2)
338
k4 = self.module.StaticTuple(k2, k1)
339
self.assertCompareDifferent(k3, k4)
340
k5 = self.module.StaticTuple(1)
341
k6 = self.module.StaticTuple(2)
342
self.assertCompareDifferent(k5, k6)
343
k7 = self.module.StaticTuple(1.2)
344
k8 = self.module.StaticTuple(2.4)
345
self.assertCompareDifferent(k7, k8)
346
k9 = self.module.StaticTuple(u's\xb5')
347
k10 = self.module.StaticTuple(u's\xe5')
348
self.assertCompareDifferent(k9, k10)
350
def test_compare_some_different(self):
351
k1 = self.module.StaticTuple('foo', 'bar')
352
k2 = self.module.StaticTuple('foo', 'zzz')
353
self.assertCompareDifferent(k1, k2)
354
k3 = self.module.StaticTuple(k1, k1)
355
k4 = self.module.StaticTuple(k1, k2)
356
self.assertCompareDifferent(k3, k4)
357
k5 = self.module.StaticTuple('foo', None)
358
self.assertCompareDifferent(k5, k1, mismatched_types=True)
359
self.assertCompareDifferent(k5, k2, mismatched_types=True)
361
def test_compare_diff_width(self):
362
k1 = self.module.StaticTuple('foo')
363
k2 = self.module.StaticTuple('foo', 'bar')
364
self.assertCompareDifferent(k1, k2)
365
k3 = self.module.StaticTuple(k1)
366
k4 = self.module.StaticTuple(k1, k2)
367
self.assertCompareDifferent(k3, k4)
369
def test_compare_different_types(self):
370
k1 = self.module.StaticTuple('foo', 'bar')
371
k2 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
373
self.assertCompareNoRelation(k1, k2, mismatched_types=True)
374
k3 = self.module.StaticTuple('foo')
375
self.assertCompareDifferent(k3, k1)
376
k4 = self.module.StaticTuple(None)
377
self.assertCompareDifferent(k4, k1, mismatched_types=True)
378
k5 = self.module.StaticTuple(1)
379
self.assertCompareNoRelation(k1, k5, mismatched_types=True)
381
def test_compare_to_tuples(self):
382
k1 = self.module.StaticTuple('foo')
383
self.assertCompareEqual(k1, ('foo',))
384
self.assertCompareEqual(('foo',), k1)
385
self.assertCompareDifferent(k1, ('foo', 'bar'))
386
self.assertCompareDifferent(k1, ('foo', 10))
388
k2 = self.module.StaticTuple('foo', 'bar')
389
self.assertCompareEqual(k2, ('foo', 'bar'))
390
self.assertCompareEqual(('foo', 'bar'), k2)
391
self.assertCompareDifferent(k2, ('foo', 'zzz'))
392
self.assertCompareDifferent(('foo',), k2)
393
self.assertCompareDifferent(('foo', 'aaa'), k2)
394
self.assertCompareDifferent(('baz', 'bing'), k2)
395
self.assertCompareDifferent(('foo', 10), k2, mismatched_types=True)
397
k3 = self.module.StaticTuple(k1, k2)
398
self.assertCompareEqual(k3, (('foo',), ('foo', 'bar')))
399
self.assertCompareEqual((('foo',), ('foo', 'bar')), k3)
400
self.assertCompareEqual(k3, (k1, ('foo', 'bar')))
401
self.assertCompareEqual((k1, ('foo', 'bar')), k3)
403
def test_compare_mixed_depths(self):
404
stuple = self.module.StaticTuple
405
k1 = stuple(stuple('a',), stuple('b',))
406
k2 = stuple(stuple(stuple('c',), stuple('d',)),
408
# This requires comparing a StaticTuple to a 'string', and then
409
# interpreting that value in the next higher StaticTuple. This used to
410
# generate a PyErr_BadIternalCall. We now fall back to *something*.
411
self.assertCompareNoRelation(k1, k2, mismatched_types=True)
414
k = self.module.StaticTuple('foo')
415
self.assertEqual(hash(k), hash(('foo',)))
416
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
417
as_tuple = ('foo', 'bar', 'baz', 'bing')
418
self.assertEqual(hash(k), hash(as_tuple))
420
# Because k == , it replaces the slot, rather than having both
421
# present in the dict.
422
self.assertEqual('foo', x[as_tuple])
424
self.assertEqual({as_tuple: 'bar'}, x)
426
k2 = self.module.StaticTuple(k)
427
as_tuple2 = (('foo', 'bar', 'baz', 'bing'),)
428
self.assertEqual(hash(k2), hash(as_tuple2))
430
k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, 2**65, True,
432
as_tuple3 = ('foo', 1, None, u'\xb5', 1.2, 2**65, True, k)
433
self.assertEqual(hash(as_tuple3), hash(k3))
435
def test_slice(self):
436
k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
437
self.assertEqual(('foo', 'bar'), k[:2])
438
self.assertEqual(('baz',), k[2:-1])
439
self.assertEqual(('foo', 'baz',), k[::2])
440
self.assertRaises(TypeError, k.__getitem__, 'not_slice')
442
def test_referents(self):
443
# We implement tp_traverse so that things like 'meliae' can measure the
444
# amount of referenced memory. Unfortunately gc.get_referents() first
445
# checks the IS_GC flag before it traverses anything. We could write a
446
# helper func, but that won't work for the generic implementation...
447
self.requireFeature(features.meliae)
448
from meliae import scanner
449
strs = ['foo', 'bar', 'baz', 'bing']
450
k = self.module.StaticTuple(*strs)
451
if self.module is _static_tuple_py:
452
refs = strs + [self.module.StaticTuple]
455
self.assertEqual(sorted(refs), sorted(scanner.get_referents(k)))
457
def test_nested_referents(self):
458
self.requireFeature(features.meliae)
459
from meliae import scanner
460
strs = ['foo', 'bar', 'baz', 'bing']
461
k1 = self.module.StaticTuple(*strs[:2])
462
k2 = self.module.StaticTuple(*strs[2:])
463
k3 = self.module.StaticTuple(k1, k2)
465
if self.module is _static_tuple_py:
466
refs.append(self.module.StaticTuple)
467
self.assertEqual(sorted(refs),
468
sorted(scanner.get_referents(k3)))
470
def test_empty_is_singleton(self):
471
key = self.module.StaticTuple()
472
self.assertIs(key, self.module._empty_tuple)
474
def test_intern(self):
475
unique_str1 = 'unique str ' + osutils.rand_chars(20)
476
unique_str2 = 'unique str ' + osutils.rand_chars(20)
477
key = self.module.StaticTuple(unique_str1, unique_str2)
478
self.assertFalse(key in self.module._interned_tuples)
479
key2 = self.module.StaticTuple(unique_str1, unique_str2)
480
self.assertEqual(key, key2)
481
self.assertIsNot(key, key2)
483
self.assertIs(key, key3)
484
self.assertTrue(key in self.module._interned_tuples)
485
self.assertEqual(key, self.module._interned_tuples[key])
487
self.assertIs(key, key2)
489
def test__c_intern_handles_refcount(self):
490
if self.module is _static_tuple_py:
491
return # Not applicable
492
unique_str1 = 'unique str ' + osutils.rand_chars(20)
493
unique_str2 = 'unique str ' + osutils.rand_chars(20)
494
key = self.module.StaticTuple(unique_str1, unique_str2)
495
self.assertRefcount(1, key)
496
self.assertFalse(key in self.module._interned_tuples)
497
self.assertFalse(key._is_interned())
498
key2 = self.module.StaticTuple(unique_str1, unique_str2)
499
self.assertRefcount(1, key)
500
self.assertRefcount(1, key2)
501
self.assertEqual(key, key2)
502
self.assertIsNot(key, key2)
505
self.assertIs(key, key3)
506
self.assertTrue(key in self.module._interned_tuples)
507
self.assertEqual(key, self.module._interned_tuples[key])
508
# key and key3, but we 'hide' the one in _interned_tuples
509
self.assertRefcount(2, key)
511
self.assertRefcount(1, key)
512
self.assertTrue(key._is_interned())
513
self.assertRefcount(1, key2)
515
# key3 now points to key as well, and *not* to key2
516
self.assertRefcount(2, key)
517
self.assertRefcount(1, key2)
518
self.assertIs(key, key3)
519
self.assertIsNot(key3, key2)
522
self.assertRefcount(1, key)
524
def test__c_keys_are_not_immortal(self):
525
if self.module is _static_tuple_py:
526
return # Not applicable
527
unique_str1 = 'unique str ' + osutils.rand_chars(20)
528
unique_str2 = 'unique str ' + osutils.rand_chars(20)
529
key = self.module.StaticTuple(unique_str1, unique_str2)
530
self.assertFalse(key in self.module._interned_tuples)
531
self.assertRefcount(1, key)
533
self.assertRefcount(1, key)
534
self.assertTrue(key in self.module._interned_tuples)
535
self.assertTrue(key._is_interned())
537
# Create a new entry, which would point to the same location
538
key = self.module.StaticTuple(unique_str1, unique_str2)
539
self.assertRefcount(1, key)
540
# This old entry in _interned_tuples should be gone
541
self.assertFalse(key in self.module._interned_tuples)
542
self.assertFalse(key._is_interned())
544
def test__c_has_C_API(self):
545
if self.module is _static_tuple_py:
547
self.assertIsNot(None, self.module._C_API)
549
def test_from_sequence_tuple(self):
550
st = self.module.StaticTuple.from_sequence(('foo', 'bar'))
551
self.assertIsInstance(st, self.module.StaticTuple)
552
self.assertEqual(('foo', 'bar'), st)
554
def test_from_sequence_str(self):
555
st = self.module.StaticTuple.from_sequence('foo')
556
self.assertIsInstance(st, self.module.StaticTuple)
557
self.assertEqual(('f', 'o', 'o'), st)
559
def test_from_sequence_list(self):
560
st = self.module.StaticTuple.from_sequence(['foo', 'bar'])
561
self.assertIsInstance(st, self.module.StaticTuple)
562
self.assertEqual(('foo', 'bar'), st)
564
def test_from_sequence_static_tuple(self):
565
st = self.module.StaticTuple('foo', 'bar')
566
st2 = self.module.StaticTuple.from_sequence(st)
567
# If the source is a StaticTuple already, we return the exact object
568
self.assertIs(st, st2)
570
def test_from_sequence_not_sequence(self):
571
self.assertRaises(TypeError,
572
self.module.StaticTuple.from_sequence, object())
573
self.assertRaises(TypeError,
574
self.module.StaticTuple.from_sequence, 10)
576
def test_from_sequence_incorrect_args(self):
577
self.assertRaises(TypeError,
578
self.module.StaticTuple.from_sequence, object(), 'a')
579
self.assertRaises(TypeError,
580
self.module.StaticTuple.from_sequence, foo='a')
582
def test_from_sequence_iterable(self):
583
st = self.module.StaticTuple.from_sequence(iter(['foo', 'bar']))
584
self.assertIsInstance(st, self.module.StaticTuple)
585
self.assertEqual(('foo', 'bar'), st)
587
def test_from_sequence_generator(self):
588
def generate_tuple():
591
st = self.module.StaticTuple.from_sequence(generate_tuple())
592
self.assertIsInstance(st, self.module.StaticTuple)
593
self.assertEqual(('foo', 'bar'), st)
595
def test_pickle(self):
596
st = self.module.StaticTuple('foo', 'bar')
597
pickled = pickle.dumps(st)
598
unpickled = pickle.loads(pickled)
599
self.assertEqual(unpickled, st)
601
def test_pickle_empty(self):
602
st = self.module.StaticTuple()
603
pickled = pickle.dumps(st)
604
unpickled = pickle.loads(pickled)
605
self.assertIs(st, unpickled)
607
def test_pickle_nested(self):
608
st = self.module.StaticTuple('foo', self.module.StaticTuple('bar'))
609
pickled = pickle.dumps(st)
610
unpickled = pickle.loads(pickled)
611
self.assertEqual(unpickled, st)
613
def test_static_tuple_thunk(self):
614
# Make sure the right implementation is available from
615
# breezy.static_tuple.StaticTuple.
616
if self.module is _static_tuple_py:
617
if compiled_static_tuple_feature.available():
618
# We will be using the C version
620
self.assertIs(static_tuple.StaticTuple,
621
self.module.StaticTuple)
624
class TestEnsureStaticTuple(tests.TestCase):
626
def test_is_static_tuple(self):
627
st = static_tuple.StaticTuple('foo')
628
st2 = static_tuple.expect_static_tuple(st)
629
self.assertIs(st, st2)
631
def test_is_tuple(self):
633
st = static_tuple.expect_static_tuple(t)
634
self.assertIsInstance(st, static_tuple.StaticTuple)
635
self.assertEqual(t, st)
637
def test_flagged_is_static_tuple(self):
638
debug.debug_flags.add('static_tuple')
639
st = static_tuple.StaticTuple('foo')
640
st2 = static_tuple.expect_static_tuple(st)
641
self.assertIs(st, st2)
643
def test_flagged_is_tuple(self):
644
debug.debug_flags.add('static_tuple')
646
self.assertRaises(TypeError, static_tuple.expect_static_tuple, t)