~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Martin Pool
  • Date: 2005-08-30 04:47:42 UTC
  • Revision ID: mbp@sourcefrog.net-20050830044742-0437d5b674f9ccaf
- change conflict markers to suit smerge, etc

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.
228
232
        If a single string is based, it is split into words.
229
233
        For commands that are not simple space-separated words, please
230
234
        pass a list instead."""
231
 
        try:
232
 
            import shutil
233
 
            from subprocess import call
234
 
        except ImportError, e:
235
 
            _need_subprocess()
236
 
            raise
237
235
        cmd = self._formcmd(cmd)
238
236
        self.log('$ ' + ' '.join(cmd))
239
 
        actual_retcode = call(cmd, stdout=self._log_file, stderr=self._log_file)
 
237
        actual_retcode = subprocess.call(cmd, stdout=self._log_file,
 
238
                                         stderr=self._log_file)
240
239
        if retcode != actual_retcode:
241
240
            raise CommandFailed("test failed: %r returned %d, expected %d"
242
241
                                % (cmd, actual_retcode, retcode))
243
242
 
244
243
    def backtick(self, cmd, retcode=0):
245
244
        """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
245
        cmd = self._formcmd(cmd)
254
 
        child = Popen(cmd, stdout=PIPE, stderr=self._log_file)
 
246
        child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=self._log_file)
255
247
        outd, errd = child.communicate()
256
248
        self.log(outd)
257
249
        actual_retcode = child.wait()