~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Martin Pool
  • Date: 2005-09-02 02:06:23 UTC
  • Revision ID: mbp@sourcefrog.net-20050902020623-40a3a7b183da2b12
- make 0.0.7 release

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import tempfile
21
21
import os
22
22
import sys
 
23
import subprocess
23
24
 
24
25
from testsweet import run_suite
25
26
import bzrlib.commands
27
28
import bzrlib.trace
28
29
import bzrlib.fetch
29
30
 
 
31
 
30
32
MODULES_TO_TEST = []
31
33
MODULES_TO_DOCTEST = []
32
34
 
33
35
from logging import debug, warning, error
34
36
 
 
37
class CommandFailed(Exception):
 
38
    pass
35
39
 
36
40
class TestCase(unittest.TestCase):
37
41
    """Base class for bzr unit tests.
101
105
                                       bzrlib.commands.run_bzr, args)
102
106
        self.assertEquals(result, retcode)
103
107
        
 
108
        
104
109
    def check_inventory_shape(self, inv, shape):
105
110
        """
106
111
        Compare an inventory to a list of expected names.
139
144
        real_stdin = sys.stdin
140
145
        real_stdout = sys.stdout
141
146
        real_stderr = sys.stderr
142
 
        result = None
143
147
        try:
144
148
            sys.stdout = stdout
145
149
            sys.stderr = stderr
146
150
            sys.stdin = stdin
147
 
            result = a_callable(*args, **kwargs)
 
151
            return a_callable(*args, **kwargs)
148
152
        finally:
149
153
            sys.stdout = real_stdout
150
154
            sys.stderr = real_stderr
151
155
            sys.stdin = real_stdin
152
 
        return result
153
156
 
154
157
 
155
158
BzrTestBase = TestCase
228
231
        If a single string is based, it is split into words.
229
232
        For commands that are not simple space-separated words, please
230
233
        pass a list instead."""
231
 
        try:
232
 
            import shutil
233
 
            from subprocess import call
234
 
        except ImportError, e:
235
 
            _need_subprocess()
236
 
            raise
237
234
        cmd = self._formcmd(cmd)
238
235
        self.log('$ ' + ' '.join(cmd))
239
 
        actual_retcode = call(cmd, stdout=self._log_file, stderr=self._log_file)
 
236
        actual_retcode = subprocess.call(cmd, stdout=self._log_file,
 
237
                                         stderr=self._log_file)
240
238
        if retcode != actual_retcode:
241
239
            raise CommandFailed("test failed: %r returned %d, expected %d"
242
240
                                % (cmd, actual_retcode, retcode))
243
241
 
244
242
    def backtick(self, cmd, retcode=0):
245
243
        """Run a command and return its output"""
246
 
        try:
247
 
            import shutil
248
 
            from subprocess import Popen, PIPE
249
 
        except ImportError, e:
250
 
            _need_subprocess()
251
 
            raise
252
 
 
253
244
        cmd = self._formcmd(cmd)
254
 
        child = Popen(cmd, stdout=PIPE, stderr=self._log_file)
 
245
        child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=self._log_file)
255
246
        outd, errd = child.communicate()
256
247
        self.log(outd)
257
248
        actual_retcode = child.wait()
314
305
 
315
306
    testmod_names = \
316
307
                  ['bzrlib.selftest.MetaTestLog',
 
308
                   'bzrlib.selftest.test_parent',
317
309
                   'bzrlib.selftest.testinv',
318
310
                   'bzrlib.selftest.testfetch',
319
311
                   'bzrlib.selftest.versioning',