| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
""" |
| 18 |
utils.misc |
| 19 |
============= |
| 20 |
|
| 21 |
Miscellaneous useful methods. |
| 22 |
|
| 23 |
.. moduleauthor:: mulhern <[email protected]> |
| 24 |
""" |
| 25 |
|
| 26 |
|
| 27 |
from functools import wraps |
| 28 |
|
| 29 |
|
| 30 |
import pytest |
| 31 |
from hypothesis.core import FailedHealthCheck |
| 32 |
|
| 33 |
|
| 34 |
def is_unicode_string(value): |
| 35 |
""" |
| 36 |
Return ``True``, if ``value`` is of a real unicode string type |
| 37 |
(``unicode`` in python 2, ``str`` in python 3), ``False`` otherwise. |
| 38 |
""" |
| 39 |
return isinstance(value, str) |
| 40 |
|
| 41 |
|
| 42 |
def failed_health_check_wrapper(func): |
| 43 |
""" |
| 44 |
If the test fails a health check, calls skip(). |
| 45 |
""" |
| 46 |
|
| 47 |
@wraps(func) |
| 48 |
def the_func(*args): |
| 49 |
""" |
| 50 |
Catch a hypothesis FailedHealthCheck exception and log it as a skip. |
| 51 |
""" |
| 52 |
try: |
| 53 |
func(*args) |
| 54 |
except FailedHealthCheck: |
| 55 |
pytest.skip( |
| 56 |
"failed health check for %s() (%s: %s)" |
| 57 |
% ( |
| 58 |
func.__code__.co_name, |
| 59 |
func.__code__.co_filename, |
| 60 |
func.__code__.co_firstlineno, |
| 61 |
) |
| 62 |
) |
| 63 |
|
| 64 |
return the_func |