Skip to content

Commit 3d755b4

Browse files
committed
test: force line-directive to UTF-8
Treat the I/O data as UTF-8 rather than the system encoding, which can fallback to `C`, treating unicode data as ASCII. This improves the test coverage on Linux with Python 3.
1 parent c6a5e01 commit 3d755b4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

utils/line-directive

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from __future__ import print_function
1414

1515
import bisect
16+
import io
1617
import os
1718
import re
1819
import shlex
@@ -77,7 +78,7 @@ def _make_line_map(target_filename, stream=None):
7778
[(0, 'box', 1), (1, 'foo.bar', 3), (5, 'baz.txt', 20)]
7879
"""
7980
result = [(0, target_filename, 1)]
80-
input = stream or open(target_filename)
81+
input = stream or io.open(target_filename, encoding='utf-8')
8182
for i, l in enumerate(input.readlines()):
8283
m = line_pattern.match(l)
8384
if m:
@@ -142,7 +143,7 @@ def map_line_to_source_file(target_filename, target_line_num):
142143
map = fline_map(target_filename)
143144
index = bisect.bisect_left(map, (target_line_num, '', 0))
144145
base = map[index - 1]
145-
return base[1], base[2] + (target_line_num - base[0] - 1)
146+
return str(base[1]), base[2] + (target_line_num - base[0] - 1)
146147

147148

148149
def map_line_from_source_file(source_filename, source_line_num,

0 commit comments

Comments
 (0)