| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import pytest |
| 6 |
from scalene.scalene_profiler import Scalene |
| 7 |
from scalene.scalene_statistics import ScaleneStatistics |
| 8 |
from scalene.scalene_utility import enter_function_meta |
| 9 |
from unittest.mock import MagicMock |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class Filename(str): |
| 14 |
pass |
| 15 |
|
| 16 |
|
| 17 |
class LineNumber(int): |
| 18 |
pass |
| 19 |
|
| 20 |
|
| 21 |
def get_fully_qualified_name(frame: MagicMock) -> str: |
| 22 |
return frame.f_globals.get("__name__", "") + "." + frame.f_code.co_name |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
def mock_should_trace(filename: str, func_name: str) -> bool: |
| 27 |
return True |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
Scalene.should_trace = staticmethod(mock_should_trace) |
| 32 |
|
| 33 |
|
| 34 |
def test_enter_function_meta(): |
| 35 |
stats = ScaleneStatistics() |
| 36 |
frame = MagicMock() |
| 37 |
frame.f_code.co_filename = "mock_filename.py" |
| 38 |
frame.f_code.co_name = "<mock_function>" |
| 39 |
frame.f_back = None |
| 40 |
|
| 41 |
|
| 42 |
enter_function_meta(frame, Scalene.should_trace, stats) |
| 43 |
|
| 44 |
|
| 45 |
assert not stats.function_map |
| 46 |
assert not stats.firstline_map |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
pytest.main(["-v", __file__]) |