| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import pytest |
| 6 |
from scalene.scalene_profiler import Scalene |
| 7 |
from scalene.scalene_arguments import ScaleneArguments |
| 8 |
|
| 9 |
|
| 10 |
mock_filename = "mock_file.py" |
| 11 |
mock_lineno = 10 |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
def test_profile_this_code(monkeypatch): |
| 16 |
|
| 17 |
monkeypatch.setattr(Scalene, "_Scalene__files_to_profile", set()) |
| 18 |
Scalene._Scalene__files_to_profile.add(mock_filename) |
| 19 |
|
| 20 |
|
| 21 |
def mock_get_line_info(filename): |
| 22 |
if filename == mock_filename: |
| 23 |
return [((mock_lineno, mock_lineno + 1), mock_lineno)] |
| 24 |
return [] |
| 25 |
|
| 26 |
monkeypatch.setattr(Scalene, "get_line_info", mock_get_line_info) |
| 27 |
|
| 28 |
|
| 29 |
assert Scalene.profile_this_code(mock_filename, mock_lineno) == True |
| 30 |
|
| 31 |
|
| 32 |
assert Scalene.profile_this_code(mock_filename, mock_lineno + 100) == False |
| 33 |
|
| 34 |
|
| 35 |
assert Scalene.profile_this_code("other_file.py", mock_lineno) == False |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
def test_scalene_profiler(monkeypatch): |
| 42 |
test_profile_this_code(monkeypatch) |