Debian Codegraph @

tests/utils/misc.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2015 mulhern <[email protected]>
3
4 # This library is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU Lesser General Public License as published by the
6 # Free Software Foundation; either version 2.1 of the License, or (at your
7 # option) any later version.
8
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 # for more details.
13
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 """
18 utils.misc
19 =============
20
21 Miscellaneous useful methods.
22
23 .. moduleauthor:: mulhern <[email protected]>
24 """
25
26 # isort: STDLIB
27 from functools import wraps
28
29 # isort: THIRDPARTY
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