File: test_coverup_37.py

package info (click to toggle)
scalene 1.5.51-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,528 kB
  • sloc: cpp: 22,930; python: 13,403; javascript: 11,769; ansic: 817; makefile: 196; sh: 45
file content (33 lines) | stat: -rw-r--r-- 1,043 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
# file scalene/scalene_utility.py:42-64
# lines [42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 63, 64]
# branches ['53->54', '53->57', '54->55', '54->56', '57->58', '57->60']

import pytest
from unittest.mock import MagicMock
from scalene.scalene_utility import add_stack

def test_add_stack():
    def should_trace_mock(filename, name):
        return True

    stacks = {}
    frame = MagicMock()
    code = MagicMock()
    code.co_filename = "test_file.py"
    code.co_name = "test_function"
    code.co_qualname = "test_function"
    frame.f_code = code
    frame.f_lineno = 1
    frame.f_back = None

    # Add a stack
    add_stack(frame, should_trace_mock, stacks, 1.0, 0.5, 2)
    assert stacks == {(('test_file.py', 'test_function', 1),): (1, 1.0, 0.5, 2)}

    # Add the same stack to test the else branch
    add_stack(frame, should_trace_mock, stacks, 0.5, 0.25, 1)
    assert stacks == {(('test_file.py', 'test_function', 1),): (2, 1.5, 0.75, 3)}

# Run the test
def test_run():
    test_add_stack()