/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: Aaron Bentley
  • Date: 2009-10-23 03:35:32 UTC
  • mto: (4603.1.22 shelve-editor)
  • mto: This revision was merged to the branch mainline in revision 4795.
  • Revision ID: aaron@aaronbentley.com-20091023033532-exo2sfgc3rn1e434
Remove test code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Tests for the StaticTuple type."""
18
18
 
19
 
import cPickle
20
19
import gc
21
20
import sys
22
21
 
23
22
from bzrlib import (
24
23
    _static_tuple_py,
25
 
    debug,
26
24
    errors,
27
25
    osutils,
28
26
    static_tuple,
32
30
 
33
31
def load_tests(standard_tests, module, loader):
34
32
    """Parameterize tests for all versions of groupcompress."""
35
 
    global compiled_static_tuple_feature
36
 
    suite, compiled_static_tuple_feature = tests.permute_tests_for_extension(
37
 
        standard_tests, loader, 'bzrlib._static_tuple_py',
38
 
        'bzrlib._static_tuple_c')
39
 
    return suite
 
33
    scenarios = [
 
34
        ('python', {'module': _static_tuple_py}),
 
35
    ]
 
36
    suite = loader.suiteClass()
 
37
    if CompiledStaticTuple.available():
 
38
        from bzrlib import _static_tuple_c
 
39
        scenarios.append(('C', {'module': _static_tuple_c}))
 
40
    else:
 
41
        # the compiled module isn't available, so we add a failing test
 
42
        class FailWithoutFeature(tests.TestCase):
 
43
            def test_fail(self):
 
44
                self.requireFeature(CompiledStaticTuple)
 
45
        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
 
46
    result = tests.multiply_tests(standard_tests, scenarios, suite)
 
47
    return result
 
48
 
 
49
 
 
50
class _CompiledStaticTuple(tests.Feature):
 
51
 
 
52
    def _probe(self):
 
53
        try:
 
54
            import bzrlib._static_tuple_c
 
55
        except ImportError:
 
56
            return False
 
57
        return True
 
58
 
 
59
    def feature_name(self):
 
60
        return 'bzrlib._static_tuple_c'
 
61
 
 
62
CompiledStaticTuple = _CompiledStaticTuple()
40
63
 
41
64
 
42
65
class _Meliae(tests.Feature):
77
100
    def test_create_bad_args(self):
78
101
        args_256 = ['a']*256
79
102
        # too many args
80
 
        self.assertRaises(TypeError, self.module.StaticTuple, *args_256)
 
103
        self.assertRaises(ValueError, self.module.StaticTuple, *args_256)
81
104
        args_300 = ['a']*300
82
 
        self.assertRaises(TypeError, self.module.StaticTuple, *args_300)
 
105
        self.assertRaises(ValueError, self.module.StaticTuple, *args_300)
83
106
        # not a string
84
107
        self.assertRaises(TypeError, self.module.StaticTuple, object())
85
108
 
123
146
        k = self.module.StaticTuple('foo')
124
147
        t = k.as_tuple()
125
148
        self.assertEqual(('foo',), t)
126
 
        self.assertIsInstance(t, tuple)
127
 
        self.assertFalse(isinstance(t, self.module.StaticTuple))
128
149
        k = self.module.StaticTuple('foo', 'bar')
129
150
        t = k.as_tuple()
130
151
        self.assertEqual(('foo', 'bar'), t)
131
 
        k2 = self.module.StaticTuple(1, k)
132
 
        t = k2.as_tuple()
133
 
        self.assertIsInstance(t, tuple)
134
 
        # For pickling to work, we need to keep the sub-items as StaticTuple so
135
 
        # that it knows that they also need to be converted.
136
 
        self.assertIsInstance(t[1], self.module.StaticTuple)
137
 
        self.assertEqual((1, ('foo', 'bar')), t)
138
 
 
139
 
    def test_as_tuples(self):
140
 
        k1 = self.module.StaticTuple('foo', 'bar')
141
 
        t = static_tuple.as_tuples(k1)
142
 
        self.assertIsInstance(t, tuple)
143
 
        self.assertEqual(('foo', 'bar'), t)
144
 
        k2 = self.module.StaticTuple(1, k1)
145
 
        t = static_tuple.as_tuples(k2)
146
 
        self.assertIsInstance(t, tuple)
147
 
        self.assertIsInstance(t[1], tuple)
148
 
        self.assertEqual((1, ('foo', 'bar')), t)
149
 
        mixed = (1, k1)
150
 
        t = static_tuple.as_tuples(mixed)
151
 
        self.assertIsInstance(t, tuple)
152
 
        self.assertIsInstance(t[1], tuple)
153
 
        self.assertEqual((1, ('foo', 'bar')), t)
154
152
 
155
153
    def test_len(self):
156
154
        k = self.module.StaticTuple()
572
570
    def test_from_sequence_not_sequence(self):
573
571
        self.assertRaises(TypeError,
574
572
                          self.module.StaticTuple.from_sequence, object())
575
 
        self.assertRaises(TypeError,
576
 
                          self.module.StaticTuple.from_sequence, 10)
577
573
 
578
574
    def test_from_sequence_incorrect_args(self):
579
575
        self.assertRaises(TypeError,
581
577
        self.assertRaises(TypeError,
582
578
                          self.module.StaticTuple.from_sequence, foo='a')
583
579
 
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
 
 
615
580
    def test_static_tuple_thunk(self):
616
581
        # Make sure the right implementation is available from
617
582
        # bzrlib.static_tuple.StaticTuple.
618
583
        if self.module is _static_tuple_py:
619
 
            if compiled_static_tuple_feature.available():
 
584
            if CompiledStaticTuple.available():
620
585
                # We will be using the C version
621
586
                return
622
587
        self.assertIs(static_tuple.StaticTuple,
623
588
                      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)