Debian Codegraph @

tests/test_coverup_55.py

raw symbols SCIP
1 # file scalene/scalene_analysis.py:136-202
2 # lines [139, 140, 141, 142, 144, 146, 147, 149, 151, 152, 153, 154, 157, 158, 160, 161, 162, 163, 164, 165, 166, 168, 169, 170, 171, 172, 173, 176, 177, 181, 182, 186, 188, 189, 194, 196, 198, 199, 200, 202]
3 # branches ['146->157', '146->160', '160->161', '160->162', '162->exit', '162->163', '177->exit', '177->181', '181->177', '181->182', '182->186', '182->187', '187->194', '187->196', '199->200', '199->202']
4
5 import pytest
6 from scalene.scalene_analysis import ScaleneAnalysis
7 import ast
8
9
10 @pytest.fixture
11 def cleanup():
12 # Fixture to perform cleanup after tests
13 yield
14 # No cleanup actions needed for this test
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