~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__static_tuple.py

Merged bzr.dev into shelve-editor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the StaticTuple type."""
18
18
 
 
19
import cPickle
19
20
import gc
20
21
import sys
21
22
 
570
571
    def test_from_sequence_not_sequence(self):
571
572
        self.assertRaises(TypeError,
572
573
                          self.module.StaticTuple.from_sequence, object())
 
574
        self.assertRaises(TypeError,
 
575
                          self.module.StaticTuple.from_sequence, 10)
573
576
 
574
577
    def test_from_sequence_incorrect_args(self):
575
578
        self.assertRaises(TypeError,
577
580
        self.assertRaises(TypeError,
578
581
                          self.module.StaticTuple.from_sequence, foo='a')
579
582
 
 
583
    def test_from_sequence_iterable(self):
 
584
        st = self.module.StaticTuple.from_sequence(iter(['foo', 'bar']))
 
585
        self.assertIsInstance(st, self.module.StaticTuple)
 
586
        self.assertEqual(('foo', 'bar'), st)
 
587
 
 
588
    def test_from_sequence_generator(self):
 
589
        def generate_tuple():
 
590
            yield 'foo'
 
591
            yield 'bar'
 
592
        st = self.module.StaticTuple.from_sequence(generate_tuple())
 
593
        self.assertIsInstance(st, self.module.StaticTuple)
 
594
        self.assertEqual(('foo', 'bar'), st)
 
595
 
 
596
    def test_pickle(self):
 
597
        st = self.module.StaticTuple('foo', 'bar')
 
598
        pickled = cPickle.dumps(st)
 
599
        unpickled = cPickle.loads(pickled)
 
600
        self.assertEqual(unpickled, st)
 
601
 
 
602
    def test_pickle_empty(self):
 
603
        st = self.module.StaticTuple()
 
604
        pickled = cPickle.dumps(st)
 
605
        unpickled = cPickle.loads(pickled)
 
606
        self.assertIs(st, unpickled)
 
607
 
 
608
    def test_pickle_nested(self):
 
609
        st = self.module.StaticTuple('foo', self.module.StaticTuple('bar'))
 
610
        pickled = cPickle.dumps(st)
 
611
        unpickled = cPickle.loads(pickled)
 
612
        self.assertEqual(unpickled, st)
 
613
 
580
614
    def test_static_tuple_thunk(self):
581
615
        # Make sure the right implementation is available from
582
616
        # bzrlib.static_tuple.StaticTuple.