~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

bzr rm removes the working file

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
from pprint import pformat
37
37
import random
38
38
import re
39
 
import shlex
40
39
import stat
41
40
from subprocess import Popen, PIPE
42
41
import sys
54
53
    progress,
55
54
    ui,
56
55
    urlutils,
 
56
    workingtree,
57
57
    )
58
58
import bzrlib.branch
59
59
import bzrlib.commands
1294
1294
        if err:
1295
1295
            self.log('errors:\n%r', err)
1296
1296
        if retcode is not None:
1297
 
            self.assertEquals(retcode, result)
 
1297
            self.assertEquals(retcode, result,
 
1298
                              message='Unexpected return code')
1298
1299
        return out, err
1299
1300
 
1300
1301
    def run_bzr(self, *args, **kwargs):
1315
1316
        encoding = kwargs.pop('encoding', None)
1316
1317
        stdin = kwargs.pop('stdin', None)
1317
1318
        working_dir = kwargs.pop('working_dir', None)
1318
 
        return self.run_bzr_captured(args, retcode=retcode, encoding=encoding,
1319
 
                                     stdin=stdin, working_dir=working_dir)
 
1319
        error_regexes = kwargs.pop('error_regexes', [])
 
1320
 
 
1321
        out, err = self.run_bzr_captured(args, retcode=retcode,
 
1322
            encoding=encoding, stdin=stdin, working_dir=working_dir)
 
1323
 
 
1324
        for regex in error_regexes:
 
1325
            self.assertContainsRe(err, regex)
 
1326
        return out, err
 
1327
 
1320
1328
 
1321
1329
    def run_bzr_decode(self, *args, **kwargs):
1322
1330
        if 'encoding' in kwargs:
1349
1357
                               'commit', '--strict', '-m', 'my commit comment')
1350
1358
        """
1351
1359
        kwargs.setdefault('retcode', 3)
1352
 
        out, err = self.run_bzr(*args, **kwargs)
1353
 
        for regex in error_regexes:
1354
 
            self.assertContainsRe(err, regex)
 
1360
        out, err = self.run_bzr(error_regexes=error_regexes, *args, **kwargs)
1355
1361
        return out, err
1356
1362
 
1357
1363
    def run_bzr_subprocess(self, *args, **kwargs):
1953
1959
        self.assertEqualDiff(content, s)
1954
1960
 
1955
1961
    def failUnlessExists(self, path):
1956
 
        """Fail unless path, which may be abs or relative, exists."""
1957
 
        self.failUnless(osutils.lexists(path),path+" does not exist")
 
1962
        """Fail unless path or paths, which may be abs or relative, exist."""
 
1963
        if not isinstance(path, basestring):
 
1964
            for p in path:
 
1965
                self.failUnlessExists(p)
 
1966
        else:
 
1967
            self.failUnless(osutils.lexists(path),path+" does not exist")
1958
1968
 
1959
1969
    def failIfExists(self, path):
1960
 
        """Fail if path, which may be abs or relative, exists."""
1961
 
        self.failIf(osutils.lexists(path),path+" exists")
 
1970
        """Fail if path or paths, which may be abs or relative, exist."""
 
1971
        if not isinstance(path, basestring):
 
1972
            for p in path:
 
1973
                self.failIfExists(p)
 
1974
        else:
 
1975
            self.failIf(osutils.lexists(path),path+" exists")
 
1976
 
 
1977
    def assertInWorkingTree(self,path,root_path='.',tree=None):
 
1978
        """Assert whether path or paths are in the WorkingTree"""
 
1979
        if tree is None:
 
1980
            tree = workingtree.WorkingTree.open(root_path)
 
1981
        if not isinstance(path, basestring):
 
1982
            for p in path:
 
1983
                self.assertInWorkingTree(p,tree=tree)
 
1984
        else:
 
1985
            self.assertIsNot(tree.path2id(path), None,
 
1986
                path+' not in working tree.')
 
1987
 
 
1988
    def assertNotInWorkingTree(self,path,root_path='.',tree=None):
 
1989
        """Assert whether path or paths are not in the WorkingTree"""
 
1990
        if tree is None:
 
1991
            tree = workingtree.WorkingTree.open(root_path)
 
1992
        if not isinstance(path, basestring):
 
1993
            for p in path:
 
1994
                self.assertNotInWorkingTree(p,tree=tree)
 
1995
        else:
 
1996
            self.assertIs(tree.path2id(path), None, path+' in working tree.')
1962
1997
 
1963
1998
 
1964
1999
class TestCaseWithTransport(TestCaseInTempDir):