Skip to content

Commit 01aee4a

Browse files
datadiodecdunn2001
authored andcommitted
Fix Python test scripts for Python 3 and Windows
1 parent 59a0165 commit 01aee4a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

test/runjsontests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def safeGetLine( lines, index ):
3434

3535
def safeReadFile( path ):
3636
try:
37-
return file( path, 'rt' ).read()
37+
return open( path, 'rt', encoding = 'utf-8' ).read()
3838
except IOError as e:
3939
return '<File "%s" is missing: %s>' % (path,e)
4040

@@ -77,13 +77,13 @@ def runAllTests( jsontest_executable_path, input_dir = None,
7777
base_path = os.path.splitext(input_path)[0]
7878
actual_output = safeReadFile( base_path + '.actual' )
7979
actual_rewrite_output = safeReadFile( base_path + '.actual-rewrite' )
80-
file(base_path + '.process-output','wt').write( process_output )
80+
open(base_path + '.process-output', 'wt', encoding = 'utf-8').write( process_output )
8181
if status:
8282
print('parsing failed')
8383
failed_tests.append( (input_path, 'Parsing failed:\n' + process_output) )
8484
else:
8585
expected_output_path = os.path.splitext(input_path)[0] + '.expected'
86-
expected_output = file( expected_output_path, 'rt' ).read()
86+
expected_output = open( expected_output_path, 'rt', encoding = 'utf-8' ).read()
8787
detail = ( compareOutputs( expected_output, actual_output, 'input' )
8888
or compareOutputs( expected_output, actual_rewrite_output, 'rewrite' ) )
8989
if detail:

test/rununittests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def runAllTests( exe_path, use_valgrind=False ):
3131
if not status:
3232
print("Failed to obtain unit tests list:\n" + test_names, file=sys.stderr)
3333
return 1
34-
test_names = [name.strip() for name in test_names.strip().split('\n')]
34+
test_names = [name.strip() for name in test_names.decode('utf-8').strip().split('\n')]
3535
failures = []
3636
for name in test_names:
3737
print('TESTING %s:' % name, end=' ')

0 commit comments

Comments
 (0)