/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test__static_tuple.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    static_tuple,
31
31
    tests,
32
32
    )
 
33
from breezy.sixish import (
 
34
    PY3,
 
35
    text_type,
 
36
    )
33
37
from breezy.tests import (
34
38
    features,
35
39
    )
58
62
        # self.assertEqual(count, sys.getrefcount(obj)-1)
59
63
        # Then it works fine. Something about passing it to assertRefcount is
60
64
        # actually double-incrementing (and decrementing) the refcount
61
 
        self.assertEqual(count, sys.getrefcount(obj) - 3)
 
65
        self.assertEqual(count, sys.getrefcount(obj)-3)
62
66
 
63
67
    def test_create(self):
64
68
        k = self.module.StaticTuple('foo')
65
69
        k = self.module.StaticTuple('foo', 'bar')
66
70
 
67
71
    def test_create_bad_args(self):
68
 
        args_256 = ['a'] * 256
 
72
        args_256 = ['a']*256
69
73
        # too many args
70
74
        self.assertRaises(TypeError, self.module.StaticTuple, *args_256)
71
 
        args_300 = ['a'] * 300
 
75
        args_300 = ['a']*300
72
76
        self.assertRaises(TypeError, self.module.StaticTuple, *args_300)
73
77
        # not a string
74
78
        self.assertRaises(TypeError, self.module.StaticTuple, object())
108
112
    def test_concat_with_non_tuple(self):
109
113
        st1 = self.module.StaticTuple('foo')
110
114
        self.assertRaises(TypeError, lambda: st1 + 10)
111
 
 
 
115
        
112
116
    def test_as_tuple(self):
113
117
        k = self.module.StaticTuple('foo')
114
118
        t = k.as_tuple()
151
155
        self.assertEqual(2, len(k))
152
156
        k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'b')
153
157
        self.assertEqual(7, len(k))
154
 
        args = ['foo'] * 255
 
158
        args = ['foo']*255
155
159
        k = self.module.StaticTuple(*args)
156
160
        self.assertEqual(255, len(k))
157
161
 
170
174
        self.assertEqual('z', k[6])
171
175
        self.assertEqual('z', k[-1])
172
176
        self.assertRaises(IndexError, k.__getitem__, 7)
173
 
        self.assertRaises(IndexError, k.__getitem__, 256 + 7)
 
177
        self.assertRaises(IndexError, k.__getitem__, 256+7)
174
178
        self.assertRaises(IndexError, k.__getitem__, 12024)
175
179
        # Python's [] resolver handles the negative arguments, so we can't
176
180
        # really test StaticTuple_item() with negative values.
179
183
 
180
184
    def test_refcount(self):
181
185
        f = 'fo' + 'oo'
182
 
        num_refs = sys.getrefcount(f) - 1  # sys.getrefcount() adds one
 
186
        num_refs = sys.getrefcount(f) - 1 #sys.getrefcount() adds one
183
187
        k = self.module.StaticTuple(f)
184
188
        self.assertRefcount(num_refs + 1, f)
185
189
        b = k[0]
211
215
 
212
216
    def test_holds_int(self):
213
217
        k1 = self.module.StaticTuple(1)
214
 
 
215
218
        class subint(int):
216
219
            pass
217
220
        # But not a subclass, because subint could introduce refcycles
218
221
        self.assertRaises(TypeError, self.module.StaticTuple, subint(2))
219
222
 
 
223
    def test_holds_long(self):
 
224
        if PY3:
 
225
            self.skipTest("No long type on Python 3")
 
226
        k1 = self.module.StaticTuple(2**65)
 
227
        class sublong(long):
 
228
            pass
 
229
        # But not a subclass
 
230
        self.assertRaises(TypeError, self.module.StaticTuple, sublong(1))
 
231
 
220
232
    def test_holds_float(self):
221
233
        k1 = self.module.StaticTuple(1.2)
222
 
 
223
234
        class subfloat(float):
224
235
            pass
225
236
        self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
226
237
 
227
238
    def test_holds_bytes(self):
228
239
        k1 = self.module.StaticTuple(b'astring')
229
 
 
230
240
        class substr(bytes):
231
241
            pass
232
242
        self.assertRaises(TypeError, self.module.StaticTuple, substr(b'a'))
233
243
 
234
244
    def test_holds_unicode(self):
235
245
        k1 = self.module.StaticTuple(u'\xb5')
236
 
 
237
 
        class subunicode(str):
 
246
        class subunicode(text_type):
238
247
            pass
239
248
        self.assertRaises(TypeError, self.module.StaticTuple,
240
249
                          subunicode(u'\xb5'))
281
290
 
282
291
    def check_strict_compare(self, k1, k2, mismatched_types):
283
292
        """True if on Python 3 and stricter comparison semantics are used."""
284
 
        if mismatched_types:
 
293
        if PY3 and mismatched_types:
285
294
            for op in ("ge", "gt", "le", "lt"):
286
295
                self.assertRaises(TypeError, getattr(operator, op), k1, k2)
287
296
            return True
315
324
    def test_compare_vs_none(self):
316
325
        k1 = self.module.StaticTuple('baz', 'bing')
317
326
        self.assertCompareDifferent(None, k1, mismatched_types=True)
318
 
 
 
327
    
319
328
    def test_compare_cross_class(self):
320
329
        k1 = self.module.StaticTuple('baz', 'bing')
321
330
        self.assertCompareNoRelation(10, k1, mismatched_types=True)
443
452
            refs = strs + [self.module.StaticTuple]
444
453
        else:
445
454
            refs = strs
446
 
        def key(k):
447
 
            if isinstance(k, type):
448
 
                return (0, k)
449
 
            if isinstance(k, str):
450
 
                return (1, k)
451
 
            raise TypeError(k)
452
 
        self.assertEqual(
453
 
            sorted(refs, key=key),
454
 
            sorted(scanner.get_referents(k), key=key))
 
455
        self.assertEqual(sorted(refs), sorted(scanner.get_referents(k)))
455
456
 
456
457
    def test_nested_referents(self):
457
458
        self.requireFeature(features.meliae)
463
464
        refs = [k1, k2]
464
465
        if self.module is _static_tuple_py:
465
466
            refs.append(self.module.StaticTuple)
466
 
        def key(k):
467
 
            if isinstance(k, type):
468
 
                return (0, k)
469
 
            if isinstance(k, self.module.StaticTuple):
470
 
                return (1, k)
471
 
            raise TypeError(k)
472
 
 
473
 
        self.assertEqual(sorted(refs, key=key),
474
 
                         sorted(scanner.get_referents(k3), key=key))
 
467
        self.assertEqual(sorted(refs),
 
468
                         sorted(scanner.get_referents(k3)))
475
469
 
476
470
    def test_empty_is_singleton(self):
477
471
        key = self.module.StaticTuple()
494
488
 
495
489
    def test__c_intern_handles_refcount(self):
496
490
        if self.module is _static_tuple_py:
497
 
            return  # Not applicable
 
491
            return # Not applicable
498
492
        unique_str1 = 'unique str ' + osutils.rand_chars(20)
499
493
        unique_str2 = 'unique str ' + osutils.rand_chars(20)
500
494
        key = self.module.StaticTuple(unique_str1, unique_str2)
529
523
 
530
524
    def test__c_keys_are_not_immortal(self):
531
525
        if self.module is _static_tuple_py:
532
 
            return  # Not applicable
 
526
            return # Not applicable
533
527
        unique_str1 = 'unique str ' + osutils.rand_chars(20)
534
528
        unique_str2 = 'unique str ' + osutils.rand_chars(20)
535
529
        key = self.module.StaticTuple(unique_str1, unique_str2)