Cleanup the _warnings module

This commit is contained in:
Steven Silvester
2016-01-30 09:17:47 -06:00
parent f4483b775e
commit e24953cf74
+5 -4
View File
@@ -1,11 +1,11 @@
__all__ = ['all_warnings', 'expected_warnings']
from contextlib import contextmanager
import sys
import warnings
import inspect
import re
__all__ = ['all_warnings', 'expected_warnings', 'warn']
def warn(message, category=None, stacklevel=2):
"""A version of `warnings.warn` with a default stacklevel of 2.
@@ -98,7 +98,8 @@ def expected_warnings(matching):
that may produce different warnings. The behaviors can be combined.
If you pass multiple patterns, you get an orderless "and", where all of the
warnings must be raised.
If you use the "|" operator in a pattern, you can catch one of several warnings.
If you use the "|" operator in a pattern, you can catch one of several
warnings.
Finally, you can use "|\A\Z" in a pattern to signify it as optional.
"""
@@ -106,7 +107,7 @@ def expected_warnings(matching):
# enter context
yield w
# exited user context, check the recorded warnings
remaining = [m for m in matching if not '\A\Z' in m.split('|')]
remaining = [m for m in matching if '\A\Z' not in m.split('|')]
for warn in w:
found = False
for match in matching: