| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 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 |
|
| 36 |
def test_run(): |
| 37 |
test_add_stack() |