mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-01-31 14:39:52 +01:00
py2 and py3
This commit is contained in:
parent
01aee4a0dc
commit
cd140b5141
@ -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')
|
||||||
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user