| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import pytest |
| 6 |
from scalene.scalene_profiler import Scalene |
| 7 |
from scalene.scalene_statistics import StackFrame, StackStats |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
@pytest.fixture |
| 12 |
def scalene_profiler(): |
| 13 |
|
| 14 |
yield Scalene |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
def test_print_stacks(capsys, scalene_profiler): |
| 19 |
|
| 20 |
stack1 = StackFrame("test_file1.py", "test_function1", 1) |
| 21 |
stack2 = StackFrame("test_file2.py", "test_function2", 2) |
| 22 |
stats1 = StackStats(1, 1.0, 0.5, 2) |
| 23 |
stats2 = StackStats(2, 2.0, 1.0, 4) |
| 24 |
|
| 25 |
|
| 26 |
scalene_profiler._Scalene__stats.stacks = {(stack1,): stats1, (stack2,): stats2} |
| 27 |
|
| 28 |
|
| 29 |
scalene_profiler.print_stacks() |
| 30 |
|
| 31 |
|
| 32 |
captured = capsys.readouterr() |
| 33 |
|
| 34 |
|
| 35 |
assert "test_file1.py" in captured.out |
| 36 |
assert "test_function1" in captured.out |
| 37 |
assert "test_file2.py" in captured.out |
| 38 |
assert "test_function2" in captured.out |