/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: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

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
 
    )
37
33
from breezy.tests import (
38
34
    features,
39
35
    )
62
58
        # self.assertEqual(count, sys.getrefcount(obj)-1)
63
59
        # Then it works fine. Something about passing it to assertRefcount is
64
60
        # actually double-incrementing (and decrementing) the refcount
65
 
        self.assertEqual(count, sys.getrefcount(obj)-3)
 
61
        self.assertEqual(count, sys.getrefcount(obj) - 3)
66
62
 
67
63
    def test_create(self):
68
64
        k = self.module.StaticTuple('foo')
69
65
        k = self.module.StaticTuple('foo', 'bar')
70
66
 
71
67
    def test_create_bad_args(self):
72
 
        args_256 = ['a']*256
 
68
        args_256 = ['a'] * 256
73
69
        # too many args
74
70
        self.assertRaises(TypeError, self.module.StaticTuple, *args_256)
75
 
        args_300 = ['a']*300
 
71
        args_300 = ['a'] * 300
76
72
        self.assertRaises(TypeError, self.module.StaticTuple, *args_300)
77
73
        # not a string
78
74
        self.assertRaises(TypeError, self.module.StaticTuple, object())
112
108
    def test_concat_with_non_tuple(self):
113
109
        st1 = self.module.StaticTuple('foo')
114
110
        self.assertRaises(TypeError, lambda: st1 + 10)
115
 
        
 
111
 
116
112
    def test_as_tuple(self):
117
113
        k = self.module.StaticTuple('foo')
118
114
        t = k.as_tuple()
155
151
        self.assertEqual(2, len(k))
156
152
        k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'b')
157
153
        self.assertEqual(7, len(k))
158
 
        args = ['foo']*255
 
154
        args = ['foo'] * 255
159
155
        k = self.module.StaticTuple(*args)
160
156
        self.assertEqual(255, len(k))
161
157
 
174
170
        self.assertEqual('z', k[6])
175
171
        self.assertEqual('z', k[-1])
176
172
        self.assertRaises(IndexError, k.__getitem__, 7)
177
 
        self.assertRaises(IndexError, k.__getitem__, 256+7)
 
173
        self.assertRaises(IndexError, k.__getitem__, 256 + 7)
178
174
        self.assertRaises(IndexError, k.__getitem__, 12024)
179
175
        # Python's [] resolver handles the negative arguments, so we can't
180
176
        # really test StaticTuple_item() with negative values.
183
179
 
184
180
    def test_refcount(self):
185
181
        f = 'fo' + 'oo'
186
 
        num_refs = sys.getrefcount(f) - 1 #sys.getrefcount() adds one
 
182
        num_refs = sys.getrefcount(f) - 1  # sys.getrefcount() adds one
187
183
        k = self.module.StaticTuple(f)
188
184
        self.assertRefcount(num_refs + 1, f)
189
185
        b = k[0]
215
211
 
216
212
    def test_holds_int(self):
217
213
        k1 = self.module.StaticTuple(1)
 
214
 
218
215
        class subint(int):
219
216
            pass
220
217
        # But not a subclass, because subint could introduce refcycles
221
218
        self.assertRaises(TypeError, self.module.StaticTuple, subint(2))
222
219
 
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
 
 
232
220
    def test_holds_float(self):
233
221
        k1 = self.module.StaticTuple(1.2)
 
222
 
234
223
        class subfloat(float):
235
224
            pass
236
225
        self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
237
226
 
238
227
    def test_holds_bytes(self):
239
228
        k1 = self.module.StaticTuple(b'astring')
 
229
 
240
230
        class substr(bytes):
241
231
            pass
242
232
        self.assertRaises(TypeError, self.module.StaticTuple, substr(b'a'))
243
233
 
244
234
    def test_holds_unicode(self):
245
235
        k1 = self.module.StaticTuple(u'\xb5')
246
 
        class subunicode(text_type):
 
236
 
 
237
        class subunicode(str):
247
238
            pass
248
239
        self.assertRaises(TypeError, self.module.StaticTuple,
249
240
                          subunicode(u'\xb5'))
290
281
 
291
282
    def check_strict_compare(self, k1, k2, mismatched_types):
292
283
        """True if on Python 3 and stricter comparison semantics are used."""
293
 
        if PY3 and mismatched_types:
 
284
        if mismatched_types:
294
285
            for op in ("ge", "gt", "le", "lt"):
295
286
                self.assertRaises(TypeError, getattr(operator, op), k1, k2)
296
287
            return True
324
315
    def test_compare_vs_none(self):
325
316
        k1 = self.module.StaticTuple('baz', 'bing')
326
317
        self.assertCompareDifferent(None, k1, mismatched_types=True)
327
 
    
 
318
 
328
319
    def test_compare_cross_class(self):
329
320
        k1 = self.module.StaticTuple('baz', 'bing')
330
321
        self.assertCompareNoRelation(10, k1, mismatched_types=True)
488
479
 
489
480
    def test__c_intern_handles_refcount(self):
490
481
        if self.module is _static_tuple_py:
491
 
            return # Not applicable
 
482
            return  # Not applicable
492
483
        unique_str1 = 'unique str ' + osutils.rand_chars(20)
493
484
        unique_str2 = 'unique str ' + osutils.rand_chars(20)
494
485
        key = self.module.StaticTuple(unique_str1, unique_str2)
523
514
 
524
515
    def test__c_keys_are_not_immortal(self):
525
516
        if self.module is _static_tuple_py:
526
 
            return # Not applicable
 
517
            return  # Not applicable
527
518
        unique_str1 = 'unique str ' + osutils.rand_chars(20)
528
519
        unique_str2 = 'unique str ' + osutils.rand_chars(20)
529
520
        key = self.module.StaticTuple(unique_str1, unique_str2)