3
3
from __future__ import print_function
4
4
5
5
import argparse
6
+ import io
6
7
import os
7
8
import re
8
9
import subprocess
@@ -21,6 +22,7 @@ def escapeCmdArg(arg):
21
22
22
23
23
24
def run_command (cmd ):
25
+ cmd = list (map (lambda s : s .encode ('utf-8' ), cmd ))
24
26
print (' ' .join ([escapeCmdArg (arg ) for arg in cmd ]))
25
27
return subprocess .check_output (cmd , stderr = subprocess .STDOUT )
26
28
@@ -56,7 +58,7 @@ def parseLine(line, line_no, test_case, incremental_edit_args, reparse_args,
56
58
# Compute the -incremental-edit argument for swift-syntax-test
57
59
column = len (pre_edit_line ) + len (prefix ) + 1
58
60
edit_arg = '%d:%d-%d:%d=%s' % \
59
- (line_no , column , line_no , column + len (pre_edit ),
61
+ (line_no , column , line_no , column + len (pre_edit . encode ( 'utf-8' ) ),
60
62
post_edit )
61
63
incremental_edit_args .append ('-incremental-edit' )
62
64
incremental_edit_args .append (edit_arg )
@@ -102,14 +104,19 @@ def parseLine(line, line_no, test_case, incremental_edit_args, reparse_args,
102
104
# Nothing more to do
103
105
line = ''
104
106
105
- return (pre_edit_line , post_edit_line , current_reparse_start )
107
+ return (pre_edit_line .encode ('utf-8' ),
108
+ post_edit_line .encode ('utf-8' ),
109
+ current_reparse_start )
106
110
107
111
108
112
def prepareForIncrParse (test_file , test_case , pre_edit_file , post_edit_file ,
109
113
incremental_edit_args , reparse_args ):
110
- with open (test_file , mode = 'r' ) as test_file_handle , \
111
- open (pre_edit_file , mode = 'w+b' ) as pre_edit_file_handle , \
112
- open (post_edit_file , mode = 'w+b' ) as post_edit_file_handle :
114
+ with io .open (test_file , mode = 'r' , encoding = 'utf-8' ,
115
+ newline = '\n ' ) as test_file_handle , \
116
+ io .open (pre_edit_file , mode = 'w+' , encoding = 'utf-8' ,
117
+ newline = '\n ' ) as pre_edit_file_handle , \
118
+ io .open (post_edit_file , mode = 'w+' , encoding = 'utf-8' ,
119
+ newline = '\n ' ) as post_edit_file_handle :
113
120
114
121
current_reparse_start = None
115
122
@@ -121,8 +128,8 @@ def prepareForIncrParse(test_file, test_case, pre_edit_file, post_edit_file,
121
128
(pre_edit_line , post_edit_line , current_reparse_start ) = \
122
129
parseLineRes
123
130
124
- pre_edit_file_handle .write (pre_edit_line )
125
- post_edit_file_handle .write (post_edit_line )
131
+ pre_edit_file_handle .write (pre_edit_line . decode ( 'utf-8' ) )
132
+ post_edit_file_handle .write (post_edit_line . decode ( 'utf-8' ) )
126
133
127
134
line_no += 1
128
135
@@ -231,7 +238,7 @@ def serializeIncrParseMarkupFile(test_file, test_case, mode,
231
238
if print_visual_reuse_info :
232
239
print (output )
233
240
except subprocess .CalledProcessError as e :
234
- raise TestFailedError (e .output )
241
+ raise TestFailedError (e .output . decode ( 'utf-8' ) )
235
242
236
243
237
244
def main ():
0 commit comments