diff options
author | 2015-07-20 08:11:41 +0200 | |
---|---|---|
committer | 2015-07-20 08:11:41 +0200 | |
commit | 4bcb0c13f50ddb1cd3fd0341b4bb31d9c3c7fc7a (patch) | |
tree | 55eccacfca0e69435d0d4e6615205310ca11f271 /3rdparty/jsoncpp/test/pyjsontestrunner.py | |
parent | d132946c6f45aa8d271c6180e86f72dd08243048 (diff) | |
parent | 229785f695b26c702c8490792611f59d0366a933 (diff) |
Merge pull request #5 from mamedev/master
Sync to base master
Diffstat (limited to '3rdparty/jsoncpp/test/pyjsontestrunner.py')
-rw-r--r-- | 3rdparty/jsoncpp/test/pyjsontestrunner.py | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/3rdparty/jsoncpp/test/pyjsontestrunner.py b/3rdparty/jsoncpp/test/pyjsontestrunner.py index 3f08a8a7325..7f38356ae98 100644 --- a/3rdparty/jsoncpp/test/pyjsontestrunner.py +++ b/3rdparty/jsoncpp/test/pyjsontestrunner.py @@ -1,4 +1,11 @@ -# Simple implementation of a json test runner to run the test against json-py. +# Copyright 2007 Baptiste Lepilleur +# Distributed under MIT license, or public domain if desired and +# recognized in your jurisdiction. +# See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +"""Simple implementation of a json test runner to run the test against +json-py.""" + from __future__ import print_function import sys import os.path @@ -15,50 +22,50 @@ actual_path = base_path + '.actual' rewrite_path = base_path + '.rewrite' rewrite_actual_path = base_path + '.actual-rewrite' -def valueTreeToString( fout, value, path = '.' ): +def valueTreeToString(fout, value, path = '.'): ty = type(value) if ty is types.DictType: - fout.write( '%s={}\n' % path ) + fout.write('%s={}\n' % path) suffix = path[-1] != '.' and '.' or '' names = value.keys() names.sort() for name in names: - valueTreeToString( fout, value[name], path + suffix + name ) + valueTreeToString(fout, value[name], path + suffix + name) elif ty is types.ListType: - fout.write( '%s=[]\n' % path ) - for index, childValue in zip( xrange(0,len(value)), value ): - valueTreeToString( fout, childValue, path + '[%d]' % index ) + fout.write('%s=[]\n' % path) + for index, childValue in zip(xrange(0,len(value)), value): + valueTreeToString(fout, childValue, path + '[%d]' % index) elif ty is types.StringType: - fout.write( '%s="%s"\n' % (path,value) ) + fout.write('%s="%s"\n' % (path,value)) elif ty is types.IntType: - fout.write( '%s=%d\n' % (path,value) ) + fout.write('%s=%d\n' % (path,value)) elif ty is types.FloatType: - fout.write( '%s=%.16g\n' % (path,value) ) + fout.write('%s=%.16g\n' % (path,value)) elif value is True: - fout.write( '%s=true\n' % path ) + fout.write('%s=true\n' % path) elif value is False: - fout.write( '%s=false\n' % path ) + fout.write('%s=false\n' % path) elif value is None: - fout.write( '%s=null\n' % path ) + fout.write('%s=null\n' % path) else: assert False and "Unexpected value type" -def parseAndSaveValueTree( input, actual_path ): - root = json.loads( input ) - fout = file( actual_path, 'wt' ) - valueTreeToString( fout, root ) +def parseAndSaveValueTree(input, actual_path): + root = json.loads(input) + fout = file(actual_path, 'wt') + valueTreeToString(fout, root) fout.close() return root -def rewriteValueTree( value, rewrite_path ): - rewrite = json.dumps( value ) +def rewriteValueTree(value, rewrite_path): + rewrite = json.dumps(value) #rewrite = rewrite[1:-1] # Somehow the string is quoted ! jsonpy bug ? - file( rewrite_path, 'wt').write( rewrite + '\n' ) + file(rewrite_path, 'wt').write(rewrite + '\n') return rewrite -input = file( input_path, 'rt' ).read() -root = parseAndSaveValueTree( input, actual_path ) -rewrite = rewriteValueTree( json.write( root ), rewrite_path ) -rewrite_root = parseAndSaveValueTree( rewrite, rewrite_actual_path ) +input = file(input_path, 'rt').read() +root = parseAndSaveValueTree(input, actual_path) +rewrite = rewriteValueTree(json.write(root), rewrite_path) +rewrite_root = parseAndSaveValueTree(rewrite, rewrite_actual_path) -sys.exit( 0 ) +sys.exit(0) |