/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 bzrlib/tests/test__static_tuple.py

  • Committer: Andrew Bennetts
  • Date: 2009-11-19 06:28:13 UTC
  • mfrom: (4811 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4812.
  • Revision ID: andrew.bennetts@canonical.com-20091119062813-t6sd6gwbot8nfyze
MergeĀ lp:bzr.

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
 
22
23
from bzrlib import (
23
24
    _static_tuple_py,
 
25
    debug,
24
26
    errors,
25
27
    osutils,
26
28
    static_tuple,
570
572
    def test_from_sequence_not_sequence(self):
571
573
        self.assertRaises(TypeError,
572
574
                          self.module.StaticTuple.from_sequence, object())
 
575
        self.assertRaises(TypeError,
 
576
                          self.module.StaticTuple.from_sequence, 10)
573
577
 
574
578
    def test_from_sequence_incorrect_args(self):
575
579
        self.assertRaises(TypeError,
577
581
        self.assertRaises(TypeError,
578
582
                          self.module.StaticTuple.from_sequence, foo='a')
579
583
 
 
584
    def test_from_sequence_iterable(self):
 
585
        st = self.module.StaticTuple.from_sequence(iter(['foo', 'bar']))
 
586
        self.assertIsInstance(st, self.module.StaticTuple)
 
587
        self.assertEqual(('foo', 'bar'), st)
 
588
 
 
589
    def test_from_sequence_generator(self):
 
590
        def generate_tuple():
 
591
            yield 'foo'
 
592
            yield 'bar'
 
593
        st = self.module.StaticTuple.from_sequence(generate_tuple())
 
594
        self.assertIsInstance(st, self.module.StaticTuple)
 
595
        self.assertEqual(('foo', 'bar'), st)
 
596
 
 
597
    def test_pickle(self):
 
598
        st = self.module.StaticTuple('foo', 'bar')
 
599
        pickled = cPickle.dumps(st)
 
600
        unpickled = cPickle.loads(pickled)
 
601
        self.assertEqual(unpickled, st)
 
602
 
 
603
    def test_pickle_empty(self):
 
604
        st = self.module.StaticTuple()
 
605
        pickled = cPickle.dumps(st)
 
606
        unpickled = cPickle.loads(pickled)
 
607
        self.assertIs(st, unpickled)
 
608
 
 
609
    def test_pickle_nested(self):
 
610
        st = self.module.StaticTuple('foo', self.module.StaticTuple('bar'))
 
611
        pickled = cPickle.dumps(st)
 
612
        unpickled = cPickle.loads(pickled)
 
613
        self.assertEqual(unpickled, st)
 
614
 
580
615
    def test_static_tuple_thunk(self):
581
616
        # Make sure the right implementation is available from
582
617
        # bzrlib.static_tuple.StaticTuple.
586
621
                return
587
622
        self.assertIs(static_tuple.StaticTuple,
588
623
                      self.module.StaticTuple)
 
624
 
 
625
 
 
626
class TestEnsureStaticTuple(tests.TestCase):
 
627
 
 
628
    def test_is_static_tuple(self):
 
629
        st = static_tuple.StaticTuple('foo')
 
630
        st2 = static_tuple.expect_static_tuple(st)
 
631
        self.assertIs(st, st2)
 
632
 
 
633
    def test_is_tuple(self):
 
634
        t = ('foo',)
 
635
        st = static_tuple.expect_static_tuple(t)
 
636
        self.assertIsInstance(st, static_tuple.StaticTuple)
 
637
        self.assertEqual(t, st)
 
638
 
 
639
    def test_flagged_is_static_tuple(self):
 
640
        debug.debug_flags.add('static_tuple')
 
641
        st = static_tuple.StaticTuple('foo')
 
642
        st2 = static_tuple.expect_static_tuple(st)
 
643
        self.assertIs(st, st2)
 
644
 
 
645
    def test_flagged_is_tuple(self):
 
646
        debug.debug_flags.add('static_tuple')
 
647
        t = ('foo',)
 
648
        self.assertRaises(TypeError, static_tuple.expect_static_tuple, t)