~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Aaron Bentley
  • Date: 2008-03-03 16:52:41 UTC
  • mfrom: (3144.3.11 fix-conflict-handling)
  • mto: This revision was merged to the branch mainline in revision 3250.
  • Revision ID: aaron@aaronbentley.com-20080303165241-0k2c7ggs6kr9q6hf
Merge with fix-conflict-handling

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
275
275
        elif isinstance(err[1], UnavailableFeature):
276
276
            return self.addNotSupported(test, err[1].args[0])
277
277
        else:
 
278
            self._cleanupLogFile(test)
278
279
            unittest.TestResult.addError(self, test, err)
279
280
            self.error_count += 1
280
281
            self.report_error(test, err)
291
292
        if isinstance(err[1], KnownFailure):
292
293
            return self._addKnownFailure(test, err)
293
294
        else:
 
295
            self._cleanupLogFile(test)
294
296
            unittest.TestResult.addFailure(self, test, err)
295
297
            self.failure_count += 1
296
298
            self.report_failure(test, err)
310
312
                    self._formatTime(benchmark_time),
311
313
                    test.id()))
312
314
        self.report_success(test)
 
315
        self._cleanupLogFile(test)
313
316
        unittest.TestResult.addSuccess(self, test)
314
317
 
315
318
    def _testConcluded(self, test):
317
320
 
318
321
        Called regardless of whether it succeded, failed, etc.
319
322
        """
320
 
        self._cleanupLogFile(test)
 
323
        pass
321
324
 
322
325
    def _addKnownFailure(self, test, err):
323
326
        self.known_failure_count += 1
794
797
    def setUp(self):
795
798
        unittest.TestCase.setUp(self)
796
799
        self._cleanEnvironment()
797
 
        bzrlib.trace.disable_default_logging()
798
800
        self._silenceUI()
799
801
        self._startLogFile()
800
802
        self._benchcalls = []
1038
1040
        else:
1039
1041
            self.fail('Unexpected success.  Should have failed: %s' % reason)
1040
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
 
1041
1069
    def _capture_deprecation_warnings(self, a_callable, *args, **kwargs):
1042
1070
        """A helper for callDeprecated and applyDeprecated.
1043
1071
 
1156
1184
        """
1157
1185
        fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr')
1158
1186
        self._log_file = os.fdopen(fileno, 'w+')
1159
 
        self._log_nonce = bzrlib.trace.enable_test_log(self._log_file)
 
1187
        self._log_memento = bzrlib.trace.push_log_file(self._log_file)
1160
1188
        self._log_file_name = name
1161
1189
        self.addCleanup(self._finishLogFile)
1162
1190
 
1167
1195
        """
1168
1196
        if self._log_file is None:
1169
1197
            return
1170
 
        bzrlib.trace.disable_test_log(self._log_nonce)
 
1198
        bzrlib.trace.pop_log_file(self._log_memento)
1171
1199
        self._log_file.close()
1172
1200
        self._log_file = None
1173
1201
        if not self._keep_log_file:
1199
1227
            'BZREMAIL': None, # may still be present in the environment
1200
1228
            'EMAIL': None,
1201
1229
            'BZR_PROGRESS_BAR': None,
 
1230
            'BZR_LOG': None,
1202
1231
            # SSH Agent
1203
1232
            'SSH_AUTH_SOCK': None,
1204
1233
            # Proxies
1310
1339
        import bzrlib.trace
1311
1340
        bzrlib.trace._trace_file.flush()
1312
1341
        if self._log_contents:
 
1342
            # XXX: this can hardly contain the content flushed above --vila
 
1343
            # 20080128
1313
1344
            return self._log_contents
1314
1345
        if self._log_file_name is not None:
1315
1346
            logfile = open(self._log_file_name)
2083
2114
    def build_tree_contents(self, shape):
2084
2115
        build_tree_contents(shape)
2085
2116
 
2086
 
    def assertFileEqual(self, content, path):
2087
 
        """Fail if path does not contain 'content'."""
2088
 
        self.failUnlessExists(path)
2089
 
        f = file(path, 'rb')
2090
 
        try:
2091
 
            s = f.read()
2092
 
        finally:
2093
 
            f.close()
2094
 
        self.assertEqualDiff(content, s)
2095
 
 
2096
 
    def failUnlessExists(self, path):
2097
 
        """Fail unless path or paths, which may be abs or relative, exist."""
2098
 
        if not isinstance(path, basestring):
2099
 
            for p in path:
2100
 
                self.failUnlessExists(p)
2101
 
        else:
2102
 
            self.failUnless(osutils.lexists(path),path+" does not exist")
2103
 
 
2104
 
    def failIfExists(self, path):
2105
 
        """Fail if path or paths, which may be abs or relative, exist."""
2106
 
        if not isinstance(path, basestring):
2107
 
            for p in path:
2108
 
                self.failIfExists(p)
2109
 
        else:
2110
 
            self.failIf(osutils.lexists(path),path+" exists")
2111
 
 
2112
2117
    def assertInWorkingTree(self, path, root_path='.', tree=None):
2113
2118
        """Assert whether path or paths are in the WorkingTree"""
2114
2119
        if tree is None:
2811
2816
        suite.addTest(doc_suite)
2812
2817
 
2813
2818
    default_encoding = sys.getdefaultencoding()
2814
 
    for name, plugin in  [(n, p) for (n, p) in bzrlib.plugin.plugins().items()
2815
 
                          if (keep_only is None
2816
 
                              or id_filter.is_module_name_used(
2817
 
                p.module.__name__))]:
2818
 
        try:
2819
 
            plugin_suite = plugin.test_suite()
2820
 
        except ImportError, e:
2821
 
            bzrlib.trace.warning(
2822
 
                'Unable to test plugin "%s": %s', name, e)
2823
 
        else:
2824
 
            if plugin_suite is not None:
2825
 
                if keep_only is not None:
2826
 
                    plugin_suite = filter_suite_by_id_list(plugin_suite,
2827
 
                                                           id_filter)
2828
 
                suite.addTest(plugin_suite)
 
2819
    for name, plugin in bzrlib.plugin.plugins().items():
 
2820
        if keep_only is not None:
 
2821
            if not id_filter.is_module_name_used(plugin.module.__name__):
 
2822
                continue
 
2823
        plugin_suite = plugin.test_suite()
 
2824
        # We used to catch ImportError here and turn it into just a warning,
 
2825
        # but really if you don't have --no-plugins this should be a failure.
 
2826
        # mbp 20080213 - see http://bugs.launchpad.net/bugs/189771
 
2827
        if plugin_suite is not None:
 
2828
            if keep_only is not None:
 
2829
                plugin_suite = filter_suite_by_id_list(plugin_suite,
 
2830
                                                       id_filter)
 
2831
            suite.addTest(plugin_suite)
2829
2832
        if default_encoding != sys.getdefaultencoding():
2830
2833
            bzrlib.trace.warning(
2831
2834
                'Plugin "%s" tried to reset default encoding to: %s', name,
2965
2968
SymlinkFeature = _SymlinkFeature()
2966
2969
 
2967
2970
 
 
2971
class _HardlinkFeature(Feature):
 
2972
 
 
2973
    def _probe(self):
 
2974
        return osutils.has_hardlinks()
 
2975
 
 
2976
    def feature_name(self):
 
2977
        return 'hardlinks'
 
2978
 
 
2979
HardlinkFeature = _HardlinkFeature()
 
2980
 
 
2981
 
2968
2982
class _OsFifoFeature(Feature):
2969
2983
 
2970
2984
    def _probe(self):