Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: fix assert_raises_regex when used as a context manager #8093

Merged
merged 1 commit into from
Sep 26, 2016

Conversation

shoyer
Copy link
Member

@shoyer shoyer commented Sep 26, 2016

Formerly, I got DeprecationWarnings about callable being None when I tested
on Python 3.

This should fix the currently failing tests in #8054.

"""
assert_raises_regex(exception_class, expected_regexp, callable_obj=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, checking shows that unittest has

    def assertRaisesRegex(self, expected_exception, expected_regex,
                          *args, **kwargs):

e.g., no mention of callable, although the official documentation includes it as a purely positional argument. I wonder if we should just omit the =None here in the documentation and mention that when used as a context manager only the first two arguments are needed. Or maybe go all long winded and just keep the first two arguments and document the parameters with callable_obj documented as being omitted when used as context manager. The Python 3.5 documentation has

            expected_exception: Exception class expected to be raised.
            expected_regex: Regex (re pattern object or string) expected
                    to be found in error message.
            args: Function to be called and extra positional args.
            kwargs: Extra kwargs.
            msg: Optional message used in case of failure. Can only be used
                    when assertRaisesRegex is used as a context manager.

with callable omitted from the signature. Unfortunately, msg is not available in 2.7.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cleaned up the docstring, and added the two function signatures from assertRaisesRegex:
https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaisesRegex

@charris
Copy link
Member

charris commented Sep 26, 2016

This looks good, but the function documentation and signature can perhaps be improved.

Formerly, I got DeprecationWarnings about callable being None when I tested
on Python 3.
@charris charris merged commit 7ccf0e0 into numpy:master Sep 26, 2016
@charris
Copy link
Member

charris commented Sep 26, 2016

Thanks @shoyer .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants