/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-26 08:56:09 UTC
  • mfrom: (2592.3.247 mbp-writegroups)
  • Revision ID: pqm@pqm.ubuntu.com-20071026085609-c3r8skfrmjj21j0m
Unlock while in a write group now aborts the write group, unlocks, and errors.  Also includes the knit extraction one-liner tweak.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1032
1032
        else:
1033
1033
            self.fail('Unexpected success.  Should have failed: %s' % reason)
1034
1034
 
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.
1037
1037
 
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``)
1082
1082
        """
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])
1091
1091
        return result
1092
1092
 
 
1093
    def callCatchWarnings(self, fn, *args, **kw):
 
1094
        """Call a callable that raises python warnings.
 
1095
 
 
1096
        The caller's responsible for examining the returned warnings.
 
1097
 
 
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.
 
1101
 
 
1102
        :returns: ([warning_object, ...], fn_result)
 
1103
        """
 
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
 
1108
        wlist = []
 
1109
        def _catcher(message, category, filename, lineno, file=None):
 
1110
            # despite the name, 'message' is normally(?) a Warning subclass
 
1111
            # instance
 
1112
            wlist.append(message)
 
1113
        saved_showwarning = warnings.showwarning
 
1114
        saved_filters = warnings.filters
 
1115
        try:
 
1116
            warnings.showwarning = _catcher
 
1117
            warnings.filters = []
 
1118
            result = fn(*args, **kw)
 
1119
        finally:
 
1120
            warnings.showwarning = saved_showwarning
 
1121
            warnings.filters = saved_filters
 
1122
        return wlist, result
 
1123
 
1093
1124
    def callDeprecated(self, expected, callable, *args, **kwargs):
1094
1125
        """Assert that a callable is deprecated in a particular way.
1095
1126
 
1099
1130
        and will ensure that that is issued for the function being called.
1100
1131
 
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.
1103
1135
 
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
1108
1140
        """
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)
1112
1144
        return result