1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
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])
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)
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),
312
314
self.report_success(test)
315
self._cleanupLogFile(test)
313
316
unittest.TestResult.addSuccess(self, test)
315
318
def _testConcluded(self, test):
318
321
Called regardless of whether it succeded, failed, etc.
320
self._cleanupLogFile(test)
322
325
def _addKnownFailure(self, test, err):
323
326
self.known_failure_count += 1
1039
1041
self.fail('Unexpected success. Should have failed: %s' % reason)
1043
def assertFileEqual(self, content, path):
1044
"""Fail if path does not contain 'content'."""
1045
self.failUnlessExists(path)
1046
f = file(path, 'rb')
1051
self.assertEqualDiff(content, s)
1053
def failUnlessExists(self, path):
1054
"""Fail unless path or paths, which may be abs or relative, exist."""
1055
if not isinstance(path, basestring):
1057
self.failUnlessExists(p)
1059
self.failUnless(osutils.lexists(path),path+" does not exist")
1061
def failIfExists(self, path):
1062
"""Fail if path or paths, which may be abs or relative, exist."""
1063
if not isinstance(path, basestring):
1065
self.failIfExists(p)
1067
self.failIf(osutils.lexists(path),path+" exists")
1041
1069
def _capture_deprecation_warnings(self, a_callable, *args, **kwargs):
1042
1070
"""A helper for callDeprecated and applyDeprecated.
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)
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
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)
2086
def assertFileEqual(self, content, path):
2087
"""Fail if path does not contain 'content'."""
2088
self.failUnlessExists(path)
2089
f = file(path, 'rb')
2094
self.assertEqualDiff(content, s)
2096
def failUnlessExists(self, path):
2097
"""Fail unless path or paths, which may be abs or relative, exist."""
2098
if not isinstance(path, basestring):
2100
self.failUnlessExists(p)
2102
self.failUnless(osutils.lexists(path),path+" does not exist")
2104
def failIfExists(self, path):
2105
"""Fail if path or paths, which may be abs or relative, exist."""
2106
if not isinstance(path, basestring):
2108
self.failIfExists(p)
2110
self.failIf(osutils.lexists(path),path+" exists")
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)
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__))]:
2819
plugin_suite = plugin.test_suite()
2820
except ImportError, e:
2821
bzrlib.trace.warning(
2822
'Unable to test plugin "%s": %s', name, e)
2824
if plugin_suite is not None:
2825
if keep_only is not None:
2826
plugin_suite = filter_suite_by_id_list(plugin_suite,
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__):
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,
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()
2971
class _HardlinkFeature(Feature):
2974
return osutils.has_hardlinks()
2976
def feature_name(self):
2979
HardlinkFeature = _HardlinkFeature()
2968
2982
class _OsFifoFeature(Feature):
2970
2984
def _probe(self):