Skip to content

Commit 4b6d108

Browse files
committed
tests/basics/fun_code_colines: Test decoded co_lines values.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
1 parent d6b62a2 commit 4b6d108

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

tests/basics/fun_code_colines.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Check that we have sensical bytecode offsets in function.__code__.co_lines
2+
3+
def f1(x, y, obj, obj2, obj3):
4+
a = x + y # line 4: bc+4 line+4
5+
b = x - y # line 5: bc+4 line+1
6+
# line 6
7+
# line 7
8+
# line 8
9+
# line 9
10+
# line 10
11+
# line 11
12+
# line 12
13+
# line 13
14+
# line 14
15+
# line 15
16+
# line 16
17+
# line 17
18+
# line 18
19+
# line 19
20+
c = a * b # line 20: bc+4 line+15
21+
obj.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.fun() # line 21: bc+31 line+1; bc+27 line+0
22+
# line 22
23+
# line 23
24+
# line 24: bc+0 line+3
25+
# line 25
26+
# line 26
27+
# line 27: bc+0 line+3
28+
# line 28
29+
# line 29
30+
obj2.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.fun() # line 30: bc+31 line+3; bc+27 line+0
31+
# line 31
32+
# line 32
33+
# line 33: bc+0 line+3
34+
# line 34
35+
# line 35
36+
# line 36
37+
# line 37
38+
# line 38
39+
# line 39
40+
# line 40
41+
# line 41
42+
# line 42
43+
# line 43
44+
# line 44
45+
# line 45
46+
# line 46
47+
# line 47
48+
# line 48
49+
# line 49
50+
# line 50
51+
# line 51
52+
# line 52
53+
# line 53
54+
# line 54
55+
# line 55
56+
# line 56
57+
# line 57
58+
# line 58
59+
# line 59
60+
return obj3.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.fun() # line 60: bc+31 line+27; bc+27 line+0
61+
62+
def f2(x, y):
63+
a = x + y # line 63
64+
b = x - y # line 64
65+
return a * b # line 65
66+
67+
try:
68+
f1.__code__.co_lines
69+
except AttributeError:
70+
print("SKIP")
71+
raise SystemExit
72+
73+
print("f1")
74+
for start, end, line_no in f1.__code__.co_lines():
75+
print("line {} start: {}".format(line_no, start))
76+
print("line {} end: {}".format(line_no, end))
77+
78+
print("f2")
79+
for start, end, line_no in f2.__code__.co_lines():
80+
print("line {} start: {}".format(line_no, start))
81+
print("line {} end: {}".format(line_no, end))

tests/basics/fun_code_colines.py.exp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
f1
2+
line 4 start: 0
3+
line 4 end: 4
4+
line 5 start: 4
5+
line 5 end: 8
6+
line 20 start: 8
7+
line 20 end: 12
8+
line 21 start: 12
9+
line 21 end: 70
10+
line 30 start: 70
11+
line 30 end: 128
12+
line 60 start: 128
13+
line 60 end: 186
14+
f2
15+
line 63 start: 0
16+
line 63 end: 4
17+
line 64 start: 4
18+
line 64 end: 8
19+
line 65 start: 8
20+
line 65 end: 12

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy