~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

merge in lsdiff/filterdiff friendliness

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import bzrlib.trace
29
29
import bzrlib.fetch
30
30
 
 
31
 
31
32
MODULES_TO_TEST = []
32
33
MODULES_TO_DOCTEST = []
33
34
 
34
35
from logging import debug, warning, error
35
36
 
 
37
class CommandFailed(Exception):
 
38
    pass
36
39
 
37
40
class TestCase(unittest.TestCase):
38
41
    """Base class for bzr unit tests.
71
74
        
72
75
        self._log_file_name = name
73
76
 
 
77
    def run(self, result):
 
78
        self.apply_redirected(None, None, None,
 
79
                              unittest.TestCase.run, self, result)
74
80
        
75
81
    def tearDown(self):
76
82
        logging.getLogger('').removeHandler(self._log_hdlr)
102
108
                                       bzrlib.commands.run_bzr, args)
103
109
        self.assertEquals(result, retcode)
104
110
        
 
111
        
105
112
    def check_inventory_shape(self, inv, shape):
106
113
        """
107
114
        Compare an inventory to a list of expected names.
134
141
        if stdin is None:
135
142
            stdin = StringIO("")
136
143
        if stdout is None:
137
 
            stdout = self._log_file
 
144
            if hasattr(self, "_log_file"):
 
145
                stdout = self._log_file
 
146
            else:
 
147
                stdout = StringIO()
138
148
        if stderr is None:
139
 
            stderr = self._log_file
 
149
            if hasattr(self, "_log_file"):
 
150
                stderr = self._log_file
 
151
            else:
 
152
                stderr = StringIO()
140
153
        real_stdin = sys.stdin
141
154
        real_stdout = sys.stdout
142
155
        real_stderr = sys.stderr
143
 
        result = None
144
156
        try:
145
157
            sys.stdout = stdout
146
158
            sys.stderr = stderr
147
159
            sys.stdin = stdin
148
 
            result = a_callable(*args, **kwargs)
 
160
            return a_callable(*args, **kwargs)
149
161
        finally:
150
162
            sys.stdout = real_stdout
151
163
            sys.stderr = real_stderr
152
164
            sys.stdin = real_stdin
153
 
        return result
154
165
 
155
166
 
156
167
BzrTestBase = TestCase
303
314
 
304
315
    testmod_names = \
305
316
                  ['bzrlib.selftest.MetaTestLog',
 
317
                   'bzrlib.selftest.test_parent',
306
318
                   'bzrlib.selftest.testinv',
307
319
                   'bzrlib.selftest.testfetch',
308
320
                   'bzrlib.selftest.versioning',
318
330
                   'bzrlib.selftest.test_merge_core',
319
331
                   'bzrlib.selftest.test_smart_add',
320
332
                   'bzrlib.selftest.testdiff',
321
 
                   'bzrlib.fetch'
 
333
                   'bzrlib.selftest.test_xml',
 
334
                   'bzrlib.fetch',
 
335
                   'bzrlib.selftest.teststore',
 
336
                   'bzrlib.selftest.testgraph',
322
337
                   ]
323
338
 
324
339
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,