Skip to content

Commit

Permalink
Cleanup the _warnings module
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Jan 30, 2016
1 parent f4483b7 commit e24953c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions skimage/_shared/_warnings.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -98,15 +98,16 @@ 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.
"""
with all_warnings() as w:
# 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:
Expand Down

0 comments on commit e24953c

Please sign in to comment.