/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: 2010-02-12 04:33:05 UTC
  • mfrom: (5031 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5032.
  • Revision ID: andrew.bennetts@canonical.com-20100212043305-ujdbsdoviql2t7i3
MergeĀ lp:bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
def load_tests(standard_tests, module, loader):
34
34
    """Parameterize tests for all versions of groupcompress."""
35
 
    scenarios = [
36
 
        ('python', {'module': _static_tuple_py}),
37
 
    ]
38
 
    suite = loader.suiteClass()
39
 
    if CompiledStaticTuple.available():
40
 
        from bzrlib import _static_tuple_c
41
 
        scenarios.append(('C', {'module': _static_tuple_c}))
42
 
    else:
43
 
        # the compiled module isn't available, so we add a failing test
44
 
        class FailWithoutFeature(tests.TestCase):
45
 
            def test_fail(self):
46
 
                self.requireFeature(CompiledStaticTuple)
47
 
        suite.addTest(loader.loadTestsFromTestCase(FailWithoutFeature))
48
 
    result = tests.multiply_tests(standard_tests, scenarios, suite)
49
 
    return result
50
 
 
51
 
 
52
 
class _CompiledStaticTuple(tests.Feature):
53
 
 
54
 
    def _probe(self):
55
 
        try:
56
 
            import bzrlib._static_tuple_c
57
 
        except ImportError:
58
 
            return False
59
 
        return True
60
 
 
61
 
    def feature_name(self):
62
 
        return 'bzrlib._static_tuple_c'
63
 
 
64
 
CompiledStaticTuple = _CompiledStaticTuple()
 
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
65
40
 
66
41
 
67
42
class _Meliae(tests.Feature):
148
123
        k = self.module.StaticTuple('foo')
149
124
        t = k.as_tuple()
150
125
        self.assertEqual(('foo',), t)
 
126
        self.assertIsInstance(t, tuple)
 
127
        self.assertFalse(isinstance(t, self.module.StaticTuple))
151
128
        k = self.module.StaticTuple('foo', 'bar')
152
129
        t = k.as_tuple()
153
130
        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
154
 
155
155
    def test_len(self):
156
156
        k = self.module.StaticTuple()
616
616
        # Make sure the right implementation is available from
617
617
        # bzrlib.static_tuple.StaticTuple.
618
618
        if self.module is _static_tuple_py:
619
 
            if CompiledStaticTuple.available():
 
619
            if compiled_static_tuple_feature.available():
620
620
                # We will be using the C version
621
621
                return
622
622
        self.assertIs(static_tuple.StaticTuple,