Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tidy up test
  • Loading branch information
markshannon committed Jun 13, 2022
commit f2429cd59faca2b40d4838413e243440b60699ed
14 changes: 4 additions & 10 deletions Lib/test/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,21 +574,15 @@ def positions_from_location_table(code):
for _ in range(length):
yield (line, end_line, col, end_col)

def lines_from_postions(positions):
last = None
res = []
for l, _, _, _ in positions:
if l != last:
res.append(l)
last = l
return res

def dedup(lst, prev=object()):
for item in lst:
if item != prev:
yield item
prev = item

def lines_from_postions(positions):
return dedup(l for (l, _, _, _) in positions)

def misshappen():
"""

Expand Down Expand Up @@ -646,7 +640,7 @@ def test_positions(self):
def check_lines(self, func):
co = func.__code__
lines1 = list(dedup(l for (_, _, l) in co.co_lines()))
lines2 = lines_from_postions(positions_from_location_table(co))
lines2 = list(lines_from_postions(positions_from_location_table(co)))
for l1, l2 in zip(lines1, lines2):
self.assertEqual(l1, l2)
self.assertEqual(len(lines1), len(lines2))
Expand Down