~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__static_tuple.py

  • Committer: John Arbash Meinel
  • Date: 2009-10-21 14:27:00 UTC
  • mto: This revision was merged to the branch mainline in revision 4761.
  • Revision ID: john@arbash-meinel.com-20091021142700-rdadmjxsdi3kzn01
Review feedback from Andrew.

Disallow adding a subclass of str/unicode/int/float/long. Just in
case those subclasses can have refcycles.

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
    def test_concat_with_bad_tuple(self):
136
136
        st1 = self.module.StaticTuple('foo')
137
137
        t2 = (object(),)
138
 
        try:
139
 
            st3 = st1 + t2
140
 
        except TypeError:
141
 
            pass
142
 
        else:
143
 
            self.fail('TypeError not raised')
 
138
        # Using st1.__add__ doesn't give the same results as doing the '+' form
 
139
        self.assertRaises(TypeError, lambda: st1 + t2)
144
140
 
145
141
    def test_concat_with_non_tuple(self):
146
142
        st1 = self.module.StaticTuple('foo')
147
 
        try:
148
 
            st1 + 10
149
 
        except TypeError:
150
 
            pass
151
 
        else:
152
 
            self.fail('TypeError not raised for addition w/ an int')
 
143
        self.assertRaises(TypeError, lambda: st1 + 10)
153
144
        
154
145
    def test_as_tuple(self):
155
146
        k = self.module.StaticTuple('foo')
224
215
 
225
216
    def test_holds_None(self):
226
217
        k1 = self.module.StaticTuple(None)
 
218
        # You cannot subclass None anyway
227
219
 
228
220
    def test_holds_int(self):
229
221
        k1 = self.module.StaticTuple(1)
 
222
        class subint(int):
 
223
            pass
 
224
        # But not a subclass, because subint could introduce refcycles
 
225
        self.assertRaises(TypeError, self.module.StaticTuple, subint(2))
230
226
 
231
227
    def test_holds_long(self):
232
228
        k1 = self.module.StaticTuple(2L**65)
 
229
        class sublong(long):
 
230
            pass
 
231
        # But not a subclass
 
232
        self.assertRaises(TypeError, self.module.StaticTuple, sublong(1))
233
233
 
234
234
    def test_holds_float(self):
235
235
        k1 = self.module.StaticTuple(1.2)
 
236
        class subfloat(float):
 
237
            pass
 
238
        self.assertRaises(TypeError, self.module.StaticTuple, subfloat(1.5))
 
239
 
 
240
    def test_holds_str(self):
 
241
        k1 = self.module.StaticTuple('astring')
 
242
        class substr(str):
 
243
            pass
 
244
        self.assertRaises(TypeError, self.module.StaticTuple, substr('a'))
236
245
 
237
246
    def test_holds_unicode(self):
238
247
        k1 = self.module.StaticTuple(u'\xb5')
 
248
        class subunicode(unicode):
 
249
            pass
 
250
        self.assertRaises(TypeError, self.module.StaticTuple,
 
251
                          subunicode(u'\xb5'))
239
252
 
240
253
    def test_hold_bool(self):
241
254
        k1 = self.module.StaticTuple(True)
242
255
        k2 = self.module.StaticTuple(False)
 
256
        # Cannot subclass bool
243
257
 
244
258
    def test_compare_same_obj(self):
245
259
        k1 = self.module.StaticTuple('foo', 'bar')