MCPcopy Create free account
hub / github.com/numpy/numpy / FindFuncs

Class FindFuncs

numpy/tests/test_warnings.py:24–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23
24class FindFuncs(ast.NodeVisitor):
25 def __init__(self, filename):
26 super().__init__()
27 self.__filename = filename
28
29 def visit_Call(self, node):
30 p = ParseCall()
31 p.visit(node.func)
32 ast.NodeVisitor.generic_visit(self, node)
33
34 if p.ls[-1] == 'simplefilter' or p.ls[-1] == 'filterwarnings':
35 if node.args[0].value == "ignore":
36 raise AssertionError(
37 "warnings should have an appropriate stacklevel; found in "
38 "{} on line {}".format(self.__filename, node.lineno))
39
40 if p.ls[-1] == 'warn' and (
41 len(p.ls) == 1 or p.ls[-2] == 'warnings'):
42
43 if "testing/tests/test_warnings.py" == self.__filename:
44 # This file
45 return
46
47 # See if stacklevel exists:
48 if len(node.args) == 3:
49 return
50 args = {kw.arg for kw in node.keywords}
51 if "stacklevel" in args:
52 return
53 raise AssertionError(
54 "warnings should have an appropriate stacklevel; found in "
55 "{} on line {}".format(self.__filename, node.lineno))
56
57
58@pytest.mark.slow

Callers 1

test_warning_callsFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_warning_callsFunction · 0.68