~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Alexander Belchenko
  • Date: 2008-02-16 10:03:17 UTC
  • mfrom: (3224 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3230.
  • Revision ID: bialix@ukr.net-20080216100317-xg1hdw306evlgt94
merge bzr.dev; update for 1.3; $BZR_LOG used in trace.py module (again), not in the main bzr script (req. by Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 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
797
797
    def setUp(self):
798
798
        unittest.TestCase.setUp(self)
799
799
        self._cleanEnvironment()
800
 
        bzrlib.trace.disable_default_logging()
801
800
        self._silenceUI()
802
801
        self._startLogFile()
803
802
        self._benchcalls = []
1041
1040
        else:
1042
1041
            self.fail('Unexpected success.  Should have failed: %s' % reason)
1043
1042
 
 
1043
    def assertFileEqual(self, content, path):
 
1044
        """Fail if path does not contain 'content'."""
 
1045
        self.failUnlessExists(path)
 
1046
        f = file(path, 'rb')
 
1047
        try:
 
1048
            s = f.read()
 
1049
        finally:
 
1050
            f.close()
 
1051
        self.assertEqualDiff(content, s)
 
1052
 
 
1053
    def failUnlessExists(self, path):
 
1054
        """Fail unless path or paths, which may be abs or relative, exist."""
 
1055
        if not isinstance(path, basestring):
 
1056
            for p in path:
 
1057
                self.failUnlessExists(p)
 
1058
        else:
 
1059
            self.failUnless(osutils.lexists(path),path+" does not exist")
 
1060
 
 
1061
    def failIfExists(self, path):
 
1062
        """Fail if path or paths, which may be abs or relative, exist."""
 
1063
        if not isinstance(path, basestring):
 
1064
            for p in path:
 
1065
                self.failIfExists(p)
 
1066
        else:
 
1067
            self.failIf(osutils.lexists(path),path+" exists")
 
1068
 
1044
1069
    def _capture_deprecation_warnings(self, a_callable, *args, **kwargs):
1045
1070
        """A helper for callDeprecated and applyDeprecated.
1046
1071
 
1159
1184
        """
1160
1185
        fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr')
1161
1186
        self._log_file = os.fdopen(fileno, 'w+')
1162
 
        self._log_nonce = bzrlib.trace.enable_test_log(self._log_file)
 
1187
        self._log_memento = bzrlib.trace.push_log_file(self._log_file)
1163
1188
        self._log_file_name = name
1164
1189
        self.addCleanup(self._finishLogFile)
1165
1190
 
1170
1195
        """
1171
1196
        if self._log_file is None:
1172
1197
            return
1173
 
        bzrlib.trace.disable_test_log(self._log_nonce)
 
1198
        bzrlib.trace.pop_log_file(self._log_memento)
1174
1199
        self._log_file.close()
1175
1200
        self._log_file = None
1176
1201
        if not self._keep_log_file:
2089
2114
    def build_tree_contents(self, shape):
2090
2115
        build_tree_contents(shape)
2091
2116
 
2092
 
    def assertFileEqual(self, content, path):
2093
 
        """Fail if path does not contain 'content'."""
2094
 
        self.failUnlessExists(path)
2095
 
        f = file(path, 'rb')
2096
 
        try:
2097
 
            s = f.read()
2098
 
        finally:
2099
 
            f.close()
2100
 
        self.assertEqualDiff(content, s)
2101
 
 
2102
 
    def failUnlessExists(self, path):
2103
 
        """Fail unless path or paths, which may be abs or relative, exist."""
2104
 
        if not isinstance(path, basestring):
2105
 
            for p in path:
2106
 
                self.failUnlessExists(p)
2107
 
        else:
2108
 
            self.failUnless(osutils.lexists(path),path+" does not exist")
2109
 
 
2110
 
    def failIfExists(self, path):
2111
 
        """Fail if path or paths, which may be abs or relative, exist."""
2112
 
        if not isinstance(path, basestring):
2113
 
            for p in path:
2114
 
                self.failIfExists(p)
2115
 
        else:
2116
 
            self.failIf(osutils.lexists(path),path+" exists")
2117
 
 
2118
2117
    def assertInWorkingTree(self, path, root_path='.', tree=None):
2119
2118
        """Assert whether path or paths are in the WorkingTree"""
2120
2119
        if tree is None: