/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-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
        # self.assertEqual(count, sys.getrefcount(obj)-1)
63
63
        # Then it works fine. Something about passing it to assertRefcount is
64
64
        # actually double-incrementing (and decrementing) the refcount
65
 
        self.assertEqual(count, sys.getrefcount(obj)-3)
 
65
        self.assertEqual(count, sys.getrefcount(obj) - 3)
66
66
 
67
67
    def test_create(self):
68
68
        k = self.module.StaticTuple('foo')
69
69
        k = self.module.StaticTuple('foo', 'bar')
70
70
 
71
71
    def test_create_bad_args(self):
72
 
        args_256 = ['a']*256
 
72
        args_256 = ['a'] * 256
73
73
        # too many args
74
74
        self.assertRaises(TypeError, self.module.StaticTuple, *args_256)
75
 
        args_300 = ['a']*300
 
75
        args_300 = ['a'] * 300
76
76
        self.assertRaises(TypeError, self.module.StaticTuple, *args_300)
77
77
        # not a string
78
78
        self.assertRaises(TypeError, self.module.StaticTuple, object())
112
112
    def test_concat_with_non_tuple(self):
113
113
        st1 = self.module.StaticTuple('foo')
114
114
        self.assertRaises(TypeError, lambda: st1 + 10)
115
 
        
 
115
 
116
116
    def test_as_tuple(self):
117
117
        k = self.module.StaticTuple('foo')
118
118
        t = k.as_tuple()
155
155
        self.assertEqual(2, len(k))
156
156
        k = self.module.StaticTuple('foo', 'bar', 'b', 'b', 'b', 'b', 'b')
157
157
        self.assertEqual(7, len(k))
158
 
        args = ['foo']*255
 
158
        args = ['foo'] * 255
159
159
        k = self.module.StaticTuple(*args)
160
160
        self.assertEqual(255, len(k))
161
161
 
174
174
        self.assertEqual('z', k[6])
175
175
        self.assertEqual('z', k[-1])
176
176
        self.assertRaises(IndexError, k.__getitem__, 7)
177
 
        self.assertRaises(IndexError, k.__getitem__, 256+7)
 
177
        self.assertRaises(IndexError, k.__getitem__, 256 + 7)
178
178
        self.assertRaises(IndexError, k.__getitem__, 12024)
179
179
        # Python's [] resolver handles the negative arguments, so we can't
180
180
        # really test StaticTuple_item() with negative values.
183
183
 
184
184
    def test_refcount(self):
185
185
        f = 'fo' + 'oo'
186
 
        num_refs = sys.getrefcount(f) - 1 #sys.getrefcount() adds one
 
186
        num_refs = sys.getrefcount(f) - 1  # sys.getrefcount() adds one
187
187
        k = self.module.StaticTuple(f)
188
188
        self.assertRefcount(num_refs + 1, f)
189
189
        b = k[0]
215
215
 
216
216
    def test_holds_int(self):
217
217
        k1 = self.module.StaticTuple(1)
 
218
 
218
219
        class subint(int):
219
220
            pass
220
221
        # But not a subclass, because subint could introduce refcycles
224
225
        if PY3:
225
226
            self.skipTest("No long type on Python 3")
226
227
        k1 = self.module.StaticTuple(2**65)
 
228
 
227
229
        class sublong(long):
228
230
            pass
229
231
        # But not a subclass
231
233
 
232
234
    def test_holds_float(self):
233
235
        k1 = self.module.StaticTuple(1.2)
 
236
 
234
237
        class subfloat(float):
235
238
            pass
236
239
        self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
237
240
 
238
241
    def test_holds_bytes(self):
239
242
        k1 = self.module.StaticTuple(b'astring')
 
243
 
240
244
        class substr(bytes):
241
245
            pass
242
246
        self.assertRaises(TypeError, self.module.StaticTuple, substr(b'a'))
243
247
 
244
248
    def test_holds_unicode(self):
245
249
        k1 = self.module.StaticTuple(u'\xb5')
 
250
 
246
251
        class subunicode(text_type):
247
252
            pass
248
253
        self.assertRaises(TypeError, self.module.StaticTuple,
324
329
    def test_compare_vs_none(self):
325
330
        k1 = self.module.StaticTuple('baz', 'bing')
326
331
        self.assertCompareDifferent(None, k1, mismatched_types=True)
327
 
    
 
332
 
328
333
    def test_compare_cross_class(self):
329
334
        k1 = self.module.StaticTuple('baz', 'bing')
330
335
        self.assertCompareNoRelation(10, k1, mismatched_types=True)
488
493
 
489
494
    def test__c_intern_handles_refcount(self):
490
495
        if self.module is _static_tuple_py:
491
 
            return # Not applicable
 
496
            return  # Not applicable
492
497
        unique_str1 = 'unique str ' + osutils.rand_chars(20)
493
498
        unique_str2 = 'unique str ' + osutils.rand_chars(20)
494
499
        key = self.module.StaticTuple(unique_str1, unique_str2)
523
528
 
524
529
    def test__c_keys_are_not_immortal(self):
525
530
        if self.module is _static_tuple_py:
526
 
            return # Not applicable
 
531
            return  # Not applicable
527
532
        unique_str1 = 'unique str ' + osutils.rand_chars(20)
528
533
        unique_str2 = 'unique str ' + osutils.rand_chars(20)
529
534
        key = self.module.StaticTuple(unique_str1, unique_str2)