~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 04:47:49 UTC
  • mto: This revision was merged to the branch mainline in revision 4761.
  • Revision ID: john@arbash-meinel.com-20091021044749-gaadnlcy92ybn0ke
Set up a test suite for hash() and richcompare against lots of acceptable types.

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
        args_300 = ['a']*300
105
105
        self.assertRaises(ValueError, self.module.StaticTuple, *args_300)
106
106
        # not a string
107
 
        self.assertRaises(TypeError, self.module.StaticTuple, 10)
 
107
        self.assertRaises(TypeError, self.module.StaticTuple, object())
108
108
 
109
109
    def test_concat(self):
110
110
        st1 = self.module.StaticTuple('foo')
222
222
        self.assertFalse(k1 < k2)
223
223
        self.assertFalse(k1 > k2)
224
224
 
 
225
    def test_holds_None(self):
 
226
        k1 = self.module.StaticTuple(None)
 
227
 
 
228
    def test_holds_int(self):
 
229
        k1 = self.module.StaticTuple(1)
 
230
 
 
231
    def test_holds_float(self):
 
232
        k1 = self.module.StaticTuple(1.2)
 
233
 
 
234
    def test_holds_unicode(self):
 
235
        k1 = self.module.StaticTuple(u'\xb5')
 
236
 
 
237
    def test_hold_bool(self):
 
238
        k1 = self.module.StaticTuple(True)
 
239
        k2 = self.module.StaticTuple(False)
 
240
 
225
241
    def test_compare_same_obj(self):
226
242
        k1 = self.module.StaticTuple('foo', 'bar')
227
243
        self.assertCompareEqual(k1, k1)
228
244
        k2 = self.module.StaticTuple(k1, k1)
229
245
        self.assertCompareEqual(k2, k2)
 
246
        k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, True, k1)
 
247
        self.assertCompareEqual(k3, k3)
230
248
 
231
249
    def test_compare_equivalent_obj(self):
232
250
        k1 = self.module.StaticTuple('foo', 'bar')
235
253
        k3 = self.module.StaticTuple(k1, k2)
236
254
        k4 = self.module.StaticTuple(k2, k1)
237
255
        self.assertCompareEqual(k1, k2)
 
256
        k5 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, True, k1)
 
257
        k6 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, True, k1)
 
258
        self.assertCompareEqual(k5, k6)
 
259
        k7 = self.module.StaticTuple(None)
 
260
        k8 = self.module.StaticTuple(None)
 
261
        self.assertCompareEqual(k7, k8)
238
262
 
239
263
    def test_compare_similar_obj(self):
240
264
        k1 = self.module.StaticTuple('foo' + ' bar', 'bar' + ' baz')
285
309
        k3 = self.module.StaticTuple(k1, k2)
286
310
        k4 = self.module.StaticTuple(k2, k1)
287
311
        self.assertCompareDifferent(k3, k4)
 
312
        k5 = self.module.StaticTuple(1)
 
313
        k6 = self.module.StaticTuple(2)
 
314
        self.assertCompareDifferent(k5, k6)
 
315
        k7 = self.module.StaticTuple(1.2)
 
316
        k8 = self.module.StaticTuple(2.4)
 
317
        self.assertCompareDifferent(k7, k8)
 
318
        k9 = self.module.StaticTuple(u's\xb5')
 
319
        k10 = self.module.StaticTuple(u's\xe5')
 
320
        self.assertCompareDifferent(k9, k10)
288
321
 
289
322
    def test_compare_some_different(self):
290
323
        k1 = self.module.StaticTuple('foo', 'bar')
293
326
        k3 = self.module.StaticTuple(k1, k1)
294
327
        k4 = self.module.StaticTuple(k1, k2)
295
328
        self.assertCompareDifferent(k3, k4)
 
329
        k5 = self.module.StaticTuple('foo', None)
 
330
        self.assertCompareDifferent(k5, k1)
 
331
        self.assertCompareDifferent(k5, k2)
296
332
 
297
333
    def test_compare_diff_width(self):
298
334
        k1 = self.module.StaticTuple('foo')
302
338
        k4 = self.module.StaticTuple(k1, k2)
303
339
        self.assertCompareDifferent(k3, k4)
304
340
 
 
341
    def test_compare_different_types(self):
 
342
        k1 = self.module.StaticTuple('foo', 'bar')
 
343
        k2 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, True, k1)
 
344
        self.assertCompareNoRelation(k1, k2)
 
345
        k3 = self.module.StaticTuple('foo')
 
346
        self.assertCompareDifferent(k3, k1)
 
347
        k4 = self.module.StaticTuple(None)
 
348
        self.assertCompareDifferent(k4, k1)
 
349
        k5 = self.module.StaticTuple(1)
 
350
        self.assertCompareNoRelation(k1, k5)
 
351
 
305
352
    def test_compare_to_tuples(self):
306
353
        k1 = self.module.StaticTuple('foo')
307
354
        self.assertCompareEqual(k1, ('foo',))
351
398
        as_tuple2 = (('foo', 'bar', 'baz', 'bing'),)
352
399
        self.assertEqual(hash(k2), hash(as_tuple2))
353
400
 
 
401
        k3 = self.module.StaticTuple('foo', 1, None, u'\xb5', 1.2, True, k)
 
402
        as_tuple3 = ('foo', 1, None, u'\xb5', 1.2, True, k)
 
403
        self.assertEqual(hash(as_tuple3), hash(k3))
 
404
 
354
405
    def test_slice(self):
355
406
        k = self.module.StaticTuple('foo', 'bar', 'baz', 'bing')
356
407
        self.assertEqual(('foo', 'bar'), k[:2])