mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-29 12:41:38 +08:00
Merge branch 'py3/2'
This commit is contained in:
commit
e0bfb45000
@ -1,12 +1,30 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from io import open
|
||||||
|
from glob import glob
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
from glob import glob
|
|
||||||
import optparse
|
import optparse
|
||||||
|
|
||||||
VALGRIND_CMD = 'valgrind --tool=memcheck --leak-check=yes --undef-value-errors=yes '
|
VALGRIND_CMD = 'valgrind --tool=memcheck --leak-check=yes --undef-value-errors=yes '
|
||||||
|
|
||||||
|
def getStatusOutput(cmd):
|
||||||
|
"""
|
||||||
|
Return int, unicode (for both Python 2 and 3).
|
||||||
|
Note: os.popen().close() would return None for 0.
|
||||||
|
"""
|
||||||
|
pipe = os.popen(cmd)
|
||||||
|
process_output = pipe.read()
|
||||||
|
try:
|
||||||
|
# We have been using os.popen(). When we read() the result
|
||||||
|
# we get 'str' (bytes) in py2, and 'str' (unicode) in py3.
|
||||||
|
# Ugh! There must be a better way to handle this.
|
||||||
|
process_output = process_output.decode('utf-8')
|
||||||
|
except AttributeError:
|
||||||
|
pass # python3
|
||||||
|
status = pipe.close()
|
||||||
|
return status, process_output
|
||||||
def compareOutputs( expected, actual, message ):
|
def compareOutputs( expected, actual, message ):
|
||||||
expected = expected.strip().replace('\r','').split('\n')
|
expected = expected.strip().replace('\r','').split('\n')
|
||||||
actual = actual.strip().replace('\r','').split('\n')
|
actual = actual.strip().replace('\r','').split('\n')
|
||||||
@ -34,7 +52,7 @@ def compareOutputs( expected, actual, message ):
|
|||||||
|
|
||||||
def safeReadFile( path ):
|
def safeReadFile( path ):
|
||||||
try:
|
try:
|
||||||
return file( path, 'rt' ).read()
|
return open( path, 'rt', encoding = 'utf-8' ).read()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
return '<File "%s" is missing: %s>' % (path,e)
|
return '<File "%s" is missing: %s>' % (path,e)
|
||||||
|
|
||||||
@ -54,21 +72,20 @@ def runAllTests( jsontest_executable_path, input_dir = None,
|
|||||||
is_json_checker_test = (input_path in test_jsonchecker) or expect_failure
|
is_json_checker_test = (input_path in test_jsonchecker) or expect_failure
|
||||||
print('TESTING:', input_path, end=' ')
|
print('TESTING:', input_path, end=' ')
|
||||||
options = is_json_checker_test and '--json-checker' or ''
|
options = is_json_checker_test and '--json-checker' or ''
|
||||||
pipe = os.popen( '%s%s %s "%s"' % (
|
cmd = '%s%s %s "%s"' % (
|
||||||
valgrind_path, jsontest_executable_path, options,
|
valgrind_path, jsontest_executable_path, options,
|
||||||
input_path) )
|
input_path)
|
||||||
process_output = pipe.read()
|
status, process_output = getStatusOutput(cmd)
|
||||||
status = pipe.close()
|
|
||||||
if is_json_checker_test:
|
if is_json_checker_test:
|
||||||
if expect_failure:
|
if expect_failure:
|
||||||
if status is None:
|
if not status:
|
||||||
print('FAILED')
|
print('FAILED')
|
||||||
failed_tests.append( (input_path, 'Parsing should have failed:\n%s' %
|
failed_tests.append( (input_path, 'Parsing should have failed:\n%s' %
|
||||||
safeReadFile(input_path)) )
|
safeReadFile(input_path)) )
|
||||||
else:
|
else:
|
||||||
print('OK')
|
print('OK')
|
||||||
else:
|
else:
|
||||||
if status is not None:
|
if status:
|
||||||
print('FAILED')
|
print('FAILED')
|
||||||
failed_tests.append( (input_path, 'Parsing failed:\n' + process_output) )
|
failed_tests.append( (input_path, 'Parsing failed:\n' + process_output) )
|
||||||
else:
|
else:
|
||||||
@ -77,13 +94,13 @@ def runAllTests( jsontest_executable_path, input_dir = None,
|
|||||||
base_path = os.path.splitext(input_path)[0]
|
base_path = os.path.splitext(input_path)[0]
|
||||||
actual_output = safeReadFile( base_path + '.actual' )
|
actual_output = safeReadFile( base_path + '.actual' )
|
||||||
actual_rewrite_output = safeReadFile( base_path + '.actual-rewrite' )
|
actual_rewrite_output = safeReadFile( base_path + '.actual-rewrite' )
|
||||||
file(base_path + '.process-output','wt').write( process_output )
|
open(base_path + '.process-output', 'wt', encoding = 'utf-8').write( process_output )
|
||||||
if status:
|
if status:
|
||||||
print('parsing failed')
|
print('parsing failed')
|
||||||
failed_tests.append( (input_path, 'Parsing failed:\n' + process_output) )
|
failed_tests.append( (input_path, 'Parsing failed:\n' + process_output) )
|
||||||
else:
|
else:
|
||||||
expected_output_path = os.path.splitext(input_path)[0] + '.expected'
|
expected_output_path = os.path.splitext(input_path)[0] + '.expected'
|
||||||
expected_output = file( expected_output_path, 'rt' ).read()
|
expected_output = open( expected_output_path, 'rt', encoding = 'utf-8' ).read()
|
||||||
detail = ( compareOutputs( expected_output, actual_output, 'input' )
|
detail = ( compareOutputs( expected_output, actual_output, 'input' )
|
||||||
or compareOutputs( expected_output, actual_rewrite_output, 'rewrite' ) )
|
or compareOutputs( expected_output, actual_rewrite_output, 'rewrite' ) )
|
||||||
if detail:
|
if detail:
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from io import open
|
||||||
from glob import glob
|
from glob import glob
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
@ -19,7 +21,11 @@ class TestProxy(object):
|
|||||||
else:
|
else:
|
||||||
cmd = []
|
cmd = []
|
||||||
cmd.extend( [self.test_exe_path, '--test-auto'] + options )
|
cmd.extend( [self.test_exe_path, '--test-auto'] + options )
|
||||||
process = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
|
try:
|
||||||
|
process = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
|
||||||
|
except:
|
||||||
|
print(cmd)
|
||||||
|
raise
|
||||||
stdout = process.communicate()[0]
|
stdout = process.communicate()[0]
|
||||||
if process.returncode:
|
if process.returncode:
|
||||||
return False, stdout
|
return False, stdout
|
||||||
@ -31,7 +37,7 @@ def runAllTests( exe_path, use_valgrind=False ):
|
|||||||
if not status:
|
if not status:
|
||||||
print("Failed to obtain unit tests list:\n" + test_names, file=sys.stderr)
|
print("Failed to obtain unit tests list:\n" + test_names, file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
test_names = [name.strip() for name in test_names.strip().split('\n')]
|
test_names = [name.strip() for name in test_names.decode('utf-8').strip().split('\n')]
|
||||||
failures = []
|
failures = []
|
||||||
for name in test_names:
|
for name in test_names:
|
||||||
print('TESTING %s:' % name, end=' ')
|
print('TESTING %s:' % name, end=' ')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user