File tree 4 files changed +21
-2
lines changed
4 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,10 @@ class PYBEHAVIOR(object):
92
92
# PyPy has always omitted statements after return.
93
93
omit_after_return = omit_after_jump or PYPY
94
94
95
+ # Modules used to have firstlineno equal to the line number of the first
96
+ # real line of code. Now they always start at 1.
97
+ module_firstline_1 = pep626
98
+
95
99
# Coverage.py specifics.
96
100
97
101
# Are we using the C-implemented trace function?
Original file line number Diff line number Diff line change @@ -205,6 +205,12 @@ def _raw_parse(self):
205
205
if not empty :
206
206
self .raw_statements .update (self .byte_parser ._find_statements ())
207
207
208
+ # The first line of modules can lie and say 1 always, even if the first
209
+ # line of code is later. If so, map 1 to the actual first line of the
210
+ # module.
211
+ if env .PYBEHAVIOR .module_firstline_1 and self ._multiline :
212
+ self ._multiline [1 ] = min (self .raw_statements )
213
+
208
214
def first_line (self , line ):
209
215
"""Return the first line number of the statement including `line`."""
210
216
if line < 0 :
@@ -620,7 +626,9 @@ def _line__List(self, node):
620
626
return node .lineno
621
627
622
628
def _line__Module (self , node ):
623
- if node .body :
629
+ if env .PYBEHAVIOR .module_firstline_1 :
630
+ return 1
631
+ elif node .body :
624
632
return self .line_for_node (node .body [0 ])
625
633
else :
626
634
# Empty modules have no line number, they always start at 1.
Original file line number Diff line number Diff line change @@ -219,6 +219,11 @@ def check_coverage(
219
219
self .fail ("None of the missing choices matched %r" % missing_formatted )
220
220
221
221
if arcs is not None :
222
+ # print("Possible arcs:")
223
+ # print(" expected:", arcs)
224
+ # print(" actual:", analysis.arc_possibilities())
225
+ # print("Executed:")
226
+ # print(" actual:", sorted(set(analysis.arcs_executed())))
222
227
with self .delayed_assertions ():
223
228
self .assert_equal_arcs (
224
229
arcs , analysis .arc_possibilities (),
Original file line number Diff line number Diff line change @@ -25,14 +25,16 @@ def test_simple_sequence(self):
25
25
b = 3
26
26
""" ,
27
27
arcz = ".1 13 3." )
28
+ line1 = 1 if env .PYBEHAVIOR .module_firstline_1 else 2
28
29
self .check_coverage ("""\
29
30
30
31
a = 2
31
32
b = 3
32
33
33
34
c = 5
34
35
""" ,
35
- arcz = "-22 23 35 5-2" )
36
+ arcz = "-{0}2 23 35 5-{0}" .format (line1 )
37
+ )
36
38
37
39
def test_function_def (self ):
38
40
self .check_coverage ("""\
You can’t perform that action at this time.
0 commit comments