File: test_frame_tools.py

package info (click to toggle)
python-memray 1.17.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 24,396 kB
  • sloc: python: 28,451; ansic: 16,507; sh: 10,586; cpp: 8,494; javascript: 1,474; makefile: 822; awk: 12
file content (104 lines) | stat: -rw-r--r-- 3,452 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import pytest

from memray.reporters.frame_tools import is_cpython_internal
from memray.reporters.frame_tools import is_frame_from_import_system
from memray.reporters.frame_tools import is_frame_interesting


class TestFrameFiltering:
    @pytest.mark.parametrize(
        "frame, expected",
        [
            [
                (
                    "_PyEval_EvalFrameDefault",
                    "/src/python/python3.8/Python/ceval.c",
                    100,
                ),
                True,
            ],
            [
                ("_PyEvalSomeFunc", "/src/python/python3.8/Python/ceval.c", 100),
                True,
            ],
            [("VectorCall", "/src/python/python3.8/Python/ceval.c", 100), True],
            [("proxy_call", "/src/python/python3.8/Python/ceval.c", 100), True],
            [
                (
                    "function_code_fastcall",
                    "/src/python/python3.8/Modules/gcmodule.c",
                    100,
                ),
                True,
            ],
            [("somefunc", "myapp.py", 100), False],
            [("function_code_fastcall", "myapp.py", 100), False],
        ],
    )
    def test_cpython_internal_calls(self, frame, expected):
        # GIVEN/WHEN/THEN
        assert is_cpython_internal(frame) is expected

    @pytest.mark.parametrize(
        "frame, expected",
        [
            [("somefunc", "runpy.py", 100), False],
            [
                (
                    "_PyEval_EvalFrameDefault",
                    "/src/python/python3.8/Python/ceval.c",
                    100,
                ),
                False,
            ],
            [
                (
                    "PyArg_ParseTuple",
                    "/src/python/python3.8/Python/ceval.c",
                    100,
                ),
                True,
            ],
            [("somefunc", "myapp.py", 100), True],
            [
                (
                    "_PyEval_CompileCode",
                    "/src/python/python3.8/Include/code.h",
                    100,
                ),
                False,
            ],
        ],
    )
    def test_frame_interesting(self, frame, expected):
        # GIVEN/WHEN/THEN
        assert is_frame_interesting(frame) is expected

    @pytest.mark.parametrize(
        "frame, expected",
        [
            [("somefunc", "runpy.py", 100), False],
            [
                (
                    "_PyEval_EvalFrameDefault",
                    "/src/python/python3.8/Python/ceval.c",
                    100,
                ),
                False,
            ],
            [("somefunc", "<frozen importlib._blabla>", 100), True],
            [("somefunc", "<frozen something else>", 13), False],
            [("somefunc", "<frozen importlib>", 23), True],
            [("somefunc", "<frozen something._blich>", 11), False],
            [("somefunc", "ceval.c", 11), False],
            [("import_name", "ceval.c", 131), True],
            [("import_from", "ceval.c", 21), True],
            [("import_all_from", "ceval.c", 1), True],
            [("import_name", "otherfile.c", 14), False],
            [("import_from", "otherfile.c", 13), False],
            [("import_all_from", "otherfile.c", 12), False],
        ],
    )
    def test_is_frame_from_import_system(self, frame, expected):
        # GIVEN/WHEN/THEN
        assert is_frame_from_import_system(frame) is expected