Debian Codegraph @

extra_tests/test_functools.py

raw symbols SCIP
1 import functools
2 import sys
3 import os
4
5 def test_partial_stack():
6 # issue 3988
7 stack = []
8 def multiply(a, b):
9 frame = sys._getframe()
10 while frame:
11 stack.append(frame.f_code.co_name)
12 frame = frame.f_back
13 return a * b
14
15 penta = functools.partial(multiply, 5)
16 assert penta(2) == 10
17 assert len(stack) > 1
18 # Make sure partial.__call__ is not in the first few stack functions
19 assert all([f != "__call__" for f in stack[:3]])
20
21 def test_lru_cache_stack():
22 # issue 3988
23 stack = []
24 @functools.lru_cache
25 def multiply(a, b):
26 frame = sys._getframe()
27 while frame:
28 stack.append(frame.f_code.co_name)
29 frame = frame.f_back
30 return a * b
31
32 assert multiply(2, 5) == 10
33 assert len(stack) > 1
34 print(stack)
35 # Make sure _lru_cache.wrapper is not in the first few stack functions
36 assert all([f != "wrapper" for f in stack[:3]])
37