1033
1033
self.fail('Unexpected success. Should have failed: %s' % reason)
1035
def _capture_warnings(self, a_callable, *args, **kwargs):
1035
def _capture_deprecation_warnings(self, a_callable, *args, **kwargs):
1036
1036
"""A helper for callDeprecated and applyDeprecated.
1038
1038
:param a_callable: A callable to call.
1080
1080
:param kwargs: The keyword arguments for the callable
1081
1081
:return: The result of a_callable(``*args``, ``**kwargs``)
1083
call_warnings, result = self._capture_warnings(a_callable,
1083
call_warnings, result = self._capture_deprecation_warnings(a_callable,
1084
1084
*args, **kwargs)
1085
1085
expected_first_warning = symbol_versioning.deprecation_string(
1086
1086
a_callable, deprecation_format)
1090
1090
self.assertEqual(expected_first_warning, call_warnings[0])
1093
def callCatchWarnings(self, fn, *args, **kw):
1094
"""Call a callable that raises python warnings.
1096
The caller's responsible for examining the returned warnings.
1098
If the callable raises an exception, the exception is not
1099
caught and propagates up to the caller. In that case, the list
1100
of warnings is not available.
1102
:returns: ([warning_object, ...], fn_result)
1104
# XXX: This is not perfect, because it completely overrides the
1105
# warnings filters, and some code may depend on suppressing particular
1106
# warnings. It's the easiest way to insulate ourselves from -Werror,
1107
# though. -- Andrew, 20071062
1109
def _catcher(message, category, filename, lineno, file=None):
1110
# despite the name, 'message' is normally(?) a Warning subclass
1112
wlist.append(message)
1113
saved_showwarning = warnings.showwarning
1114
saved_filters = warnings.filters
1116
warnings.showwarning = _catcher
1117
warnings.filters = []
1118
result = fn(*args, **kw)
1120
warnings.showwarning = saved_showwarning
1121
warnings.filters = saved_filters
1122
return wlist, result
1093
1124
def callDeprecated(self, expected, callable, *args, **kwargs):
1094
1125
"""Assert that a callable is deprecated in a particular way.
1099
1130
and will ensure that that is issued for the function being called.
1101
1132
Note that this only captures warnings raised by symbol_versioning.warn,
1102
not other callers that go direct to the warning module.
1133
not other callers that go direct to the warning module. To catch
1134
general warnings, use callCatchWarnings.
1104
1136
:param expected: a list of the deprecation warnings expected, in order
1105
1137
:param callable: The callable to call
1106
1138
:param args: The positional arguments for the callable
1107
1139
:param kwargs: The keyword arguments for the callable
1109
call_warnings, result = self._capture_warnings(callable,
1141
call_warnings, result = self._capture_deprecation_warnings(callable,
1110
1142
*args, **kwargs)
1111
1143
self.assertEqual(expected, call_warnings)
2587
2619
if sys.platform == 'win32' and e.errno == errno.EACCES:
2588
2620
sys.stderr.write(('Permission denied: '
2589
2621
'unable to remove testing dir '
2590
'%\n' % os.path.basename(dirname)))
2622
'%s\n' % os.path.basename(dirname)))
2631
2663
SymlinkFeature = _SymlinkFeature()
2666
class _OsFifoFeature(Feature):
2669
return getattr(os, 'mkfifo', None)
2671
def feature_name(self):
2672
return 'filesystem fifos'
2674
OsFifoFeature = _OsFifoFeature()
2634
2677
class TestScenarioApplier(object):
2635
2678
"""A tool to apply scenarios to tests."""
2691
2734
except UnicodeDecodeError:
2739
class _FTPServerFeature(Feature):
2740
"""Some tests want an FTP Server, check if one is available.
2742
Right now, the only way this is available is if 'medusa' is installed.
2743
http://www.amk.ca/python/code/medusa.html
2748
import bzrlib.tests.ftp_server
2753
def feature_name(self):
2756
FTPServerFeature = _FTPServerFeature()