~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__static_tuple.py

  • Committer: Andrew Bennetts
  • Date: 2009-11-25 07:27:43 UTC
  • mto: This revision was merged to the branch mainline in revision 4825.
  • Revision ID: andrew.bennetts@canonical.com-20091125072743-v6sv4m2mkt9iyslp
Terminate SSHSubprocesses when no refs to them are left, in case .close is never called.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011 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
17
17
"""Tests for the StaticTuple type."""
18
18
 
19
19
import cPickle
 
20
import gc
20
21
import sys
21
22
 
22
23
from bzrlib import (
23
24
    _static_tuple_py,
24
25
    debug,
 
26
    errors,
25
27
    osutils,
26
28
    static_tuple,
27
29
    tests,
30
32
 
31
33
def load_tests(standard_tests, module, loader):
32
34
    """Parameterize tests for all versions of groupcompress."""
33
 
    global compiled_static_tuple_feature
34
 
    suite, compiled_static_tuple_feature = tests.permute_tests_for_extension(
35
 
        standard_tests, loader, 'bzrlib._static_tuple_py',
36
 
        'bzrlib._static_tuple_c')
37
 
    return suite
 
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()
38
65
 
39
66
 
40
67
class _Meliae(tests.Feature):
75
102
    def test_create_bad_args(self):
76
103
        args_256 = ['a']*256
77
104
        # too many args
78
 
        self.assertRaises(TypeError, self.module.StaticTuple, *args_256)
 
105
        self.assertRaises(ValueError, self.module.StaticTuple, *args_256)
79
106
        args_300 = ['a']*300
80
 
        self.assertRaises(TypeError, self.module.StaticTuple, *args_300)
 
107
        self.assertRaises(ValueError, self.module.StaticTuple, *args_300)
81
108
        # not a string
82
109
        self.assertRaises(TypeError, self.module.StaticTuple, object())
83
110
 
121
148
        k = self.module.StaticTuple('foo')
122
149
        t = k.as_tuple()
123
150
        self.assertEqual(('foo',), t)
124
 
        self.assertIsInstance(t, tuple)
125
 
        self.assertFalse(isinstance(t, self.module.StaticTuple))
126
151
        k = self.module.StaticTuple('foo', 'bar')
127
152
        t = k.as_tuple()
128
153
        self.assertEqual(('foo', 'bar'), t)
129
 
        k2 = self.module.StaticTuple(1, k)
130
 
        t = k2.as_tuple()
131
 
        self.assertIsInstance(t, tuple)
132
 
        # For pickling to work, we need to keep the sub-items as StaticTuple so
133
 
        # that it knows that they also need to be converted.
134
 
        self.assertIsInstance(t[1], self.module.StaticTuple)
135
 
        self.assertEqual((1, ('foo', 'bar')), t)
136
 
 
137
 
    def test_as_tuples(self):
138
 
        k1 = self.module.StaticTuple('foo', 'bar')
139
 
        t = static_tuple.as_tuples(k1)
140
 
        self.assertIsInstance(t, tuple)
141
 
        self.assertEqual(('foo', 'bar'), t)
142
 
        k2 = self.module.StaticTuple(1, k1)
143
 
        t = static_tuple.as_tuples(k2)
144
 
        self.assertIsInstance(t, tuple)
145
 
        self.assertIsInstance(t[1], tuple)
146
 
        self.assertEqual((1, ('foo', 'bar')), t)
147
 
        mixed = (1, k1)
148
 
        t = static_tuple.as_tuples(mixed)
149
 
        self.assertIsInstance(t, tuple)
150
 
        self.assertIsInstance(t[1], tuple)
151
 
        self.assertEqual((1, ('foo', 'bar')), t)
152
154
 
153
155
    def test_len(self):
154
156
        k = self.module.StaticTuple()
614
616
        # Make sure the right implementation is available from
615
617
        # bzrlib.static_tuple.StaticTuple.
616
618
        if self.module is _static_tuple_py:
617
 
            if compiled_static_tuple_feature.available():
 
619
            if CompiledStaticTuple.available():
618
620
                # We will be using the C version
619
621
                return
620
622
        self.assertIs(static_tuple.StaticTuple,