Debian Codegraph @

tests/test_coverup_37.py

raw symbols SCIP
1 # file scalene/scalene_utility.py:42-64
2 # lines [42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 63, 64]
3 # branches ['53->54', '53->57', '54->55', '54->56', '57->58', '57->60']
4
5 import pytest
6 from unittest.mock import MagicMock
7 from scalene.scalene_utility import add_stack
8 from scalene.scalene_statistics import StackFrame, StackStats
9 from types import FrameType
10
11
12 def test_add_stack():
13 frame = MagicMock(spec=FrameType)
14 code = MagicMock()
15 code.co_filename = "test_file.py"
16 code.co_name = "test_function"
17 code.co_qualname = "test_function"
18 frame.f_code = code
19 frame.f_lineno = 1
20 frame.f_back = None
21
22 should_trace_mock = lambda x, y: True
23 stacks = {}
24 add_stack(frame, should_trace_mock, stacks, 1.0, 0.5, 2)
25 expected_stack = StackFrame("test_file.py", "test_function", 1)
26 expected_stats = StackStats(1, 1.0, 0.5, 2)
27 assert str(stacks) == str({(expected_stack,): expected_stats})
28
29 # Test adding to existing stack
30 add_stack(frame, should_trace_mock, stacks, 0.5, 0.25, 1)
31 expected_stats = StackStats(2, 1.5, 0.75, 3)
32 assert str(stacks) == str({(expected_stack,): expected_stats})
33
34
35 # Run the test
36 def test_run():
37 test_add_stack()