~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-13 18:00:16 UTC
  • mto: This revision was merged to the branch mainline in revision 4755.
  • Revision ID: john@arbash-meinel.com-20091013180016-y9ciypkm8lor58fx
Implement StaticTuple.from_sequence()

This allows casting from something that *might* be a StaticTuple
into something that is definitely a StaticTuple, without having to
create a new instance.

Show diffs side-by-side

added added

removed removed

Lines of Context:
416
416
        if self.module is _static_tuple_py:
417
417
            return
418
418
        self.assertIsNot(None, self.module._C_API)
 
419
 
 
420
    def test_from_sequence_tuple(self):
 
421
        st = self.module.StaticTuple.from_sequence(('foo', 'bar'))
 
422
        self.assertIsInstance(st, self.module.StaticTuple)
 
423
        self.assertEqual(('foo', 'bar'), st)
 
424
 
 
425
    def test_from_sequence_str(self):
 
426
        st = self.module.StaticTuple.from_sequence('foo')
 
427
        self.assertIsInstance(st, self.module.StaticTuple)
 
428
        self.assertEqual(('f', 'o', 'o'), st)
 
429
 
 
430
    def test_from_sequence_list(self):
 
431
        st = self.module.StaticTuple.from_sequence(['foo', 'bar'])
 
432
        self.assertIsInstance(st, self.module.StaticTuple)
 
433
        self.assertEqual(('foo', 'bar'), st)
 
434
 
 
435
    def test_from_sequence_static_tuple(self):
 
436
        st = self.module.StaticTuple('foo', 'bar')
 
437
        st2 = self.module.StaticTuple.from_sequence(st)
 
438
        # If the source is a StaticTuple already, we return the exact object
 
439
        self.assertIs(st, st2)
 
440
 
 
441
    def test_from_sequence_not_sequence(self):
 
442
        self.assertRaises(TypeError,
 
443
                          self.module.StaticTuple.from_sequence, object())
 
444
 
 
445
    def test_from_sequence_incorrect_args(self):
 
446
        self.assertRaises(TypeError,
 
447
                          self.module.StaticTuple.from_sequence, object(), 'a')
 
448
        self.assertRaises(TypeError,
 
449
                          self.module.StaticTuple.from_sequence, foo='a')