[MERGE] TestCase.applyDeprecated
John Arbash Meinel
john at arbash-meinel.com
Wed Sep 6 00:04:31 BST 2006
Robert Collins wrote:
> This adds a new TestCase helper applyDeprecated. This allows you to call
> a callable which is deprecated without it spewing to the screen, just by
> suppling the deprecation format string issued for it.
>
> This is easier to use than callDeprecated in the common case.
>
> CHeers,
> Rob
>
...
> + def applyDeprecated(self, deprecation_format, a_callable, *args, **kwargs):
> + """Call a deprecated callable without warning the user.
> +
> + :param deprecation_format: The deprecation format that the callable
> + should have been deprecated with. This is the same type as the
> + parameter to deprecated_method/deprecated_function. If the
> + callable is not deprecated with this format, an assertion error
> + will be raised.
> + :param a_callable: A callable to call. This may be a bound method or
> + a regular function. It will be called with *args and **kwargs.
> + :param args: The positional arguments for the callable
> + :param kwargs: The keyword arguments for the callable
> + :return: The result of a_callable(*args, **kwargs)
> + """
> + call_warnings, result = self._capture_warnings(a_callable,
> + *args, **kwargs)
> + expected_first_warning = symbol_versioning.deprecation_string(
> + a_callable, deprecation_format)
> + if len(call_warnings) == 0:
> + raise AssertionError("No assertion generated by call to %s" %
> + a_callable)
> + self.assertEqual(expected_first_warning, call_warnings[0])
> + return result
> +
+1 except for one thing. You have a 'TestCase' object as 'self'.
Shouldn't you just call 'self.fail()' rather than raising an
AssertionError? I thought raising AssertionError was bad form.
I know we have other tests for deprecated/not deprecated, and I don't
believe we need to catch AssertionError to do so.
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060905/ca1e0a6e/attachment.pgp
More information about the bazaar
mailing list