| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
import pytest |
| 6 |
from scalene.scalene_analysis import ScaleneAnalysis |
| 7 |
import ast |
| 8 |
|
| 9 |
|
| 10 |
@pytest.fixture |
| 11 |
def cleanup(): |
| 12 |
|
| 13 |
yield |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
def test_find_outermost_loop(cleanup): |
| 18 |
source_code = """ |
| 19 |
class MyClass: |
| 20 |
def my_method(self): |
| 21 |
for i in range(10): |
| 22 |
if i % 2 == 0: |
| 23 |
with open('file.txt', 'w') as f: |
| 24 |
f.write(str(i)) |
| 25 |
else: |
| 26 |
pass |
| 27 |
""" |
| 28 |
|
| 29 |
expected_regions = { |
| 30 |
1: (1, 1), |
| 31 |
2: (2, 9), |
| 32 |
3: (3, 9), |
| 33 |
4: (4, 9), |
| 34 |
5: (4, 9), |
| 35 |
6: (4, 9), |
| 36 |
7: (4, 9), |
| 37 |
8: (4, 9), |
| 38 |
9: (4, 9), |
| 39 |
10: (10, 10), |
| 40 |
} |
| 41 |
|
| 42 |
regions = ScaleneAnalysis.find_outermost_loop(source_code) |
| 43 |
assert regions == expected_regions |