Skip to content

DRAFT: Format python for python36 #1085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/cleantests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import os

paths = []
for pattern in [ '*.actual', '*.actual-rewrite', '*.rewrite', '*.process-output' ]:
paths += glob.glob('data/' + pattern)
for pattern in ["*.actual", "*.actual-rewrite", "*.rewrite", "*.process-output"]:
paths += glob.glob("data/" + pattern)

for path in paths:
os.unlink(path)
15 changes: 7 additions & 8 deletions test/generate_expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
# recognized in your jurisdiction.
# See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE

from __future__ import print_function
import glob
import os.path
for path in glob.glob('*.json'):
text = file(path,'rt').read()
target = os.path.splitext(path)[0] + '.expected'

for path in glob.glob("*.json"):
text = file(path, "rt").read()
target = os.path.splitext(path)[0] + ".expected"
if os.path.exists(target):
print('skipping:', target)
print("skipping:", target)
else:
print('creating:', target)
file(target,'wt').write(text)

print("creating:", target)
file(target, "wt").write(text)
53 changes: 28 additions & 25 deletions test/pyjsontestrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""Simple implementation of a json test runner to run the test against
json-py."""

from __future__ import print_function
import sys
import os.path
import json
Expand All @@ -15,55 +14,59 @@
if len(sys.argv) != 2:
print("Usage: %s input-json-file", sys.argv[0])
sys.exit(3)

input_path = sys.argv[1]
base_path = os.path.splitext(input_path)[0]
actual_path = base_path + '.actual'
rewrite_path = base_path + '.rewrite'
rewrite_actual_path = base_path + '.actual-rewrite'
actual_path = base_path + ".actual"
rewrite_path = base_path + ".rewrite"
rewrite_actual_path = base_path + ".actual-rewrite"


def valueTreeToString(fout, value, path = '.'):
ty = type(value)
if ty is types.DictType:
fout.write('%s={}\n' % path)
suffix = path[-1] != '.' and '.' or ''
def valueTreeToString(fout, value, path="."):
ty = type(value)
if ty is types.DictType:
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)
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(f'{path}="{value}"\n')
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(f"{path}={value:.16g}\n")
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')
fout = file(actual_path, "wt")
valueTreeToString(fout, root)
fout.close()
return root


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')
# rewrite = rewrite[1:-1] # Somehow the string is quoted ! jsonpy bug ?
file(rewrite_path, "wt").write(rewrite + "\n")
return rewrite

input = file(input_path, 'rt').read()


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)
Expand Down
Loading