Do not value compare JSON files for regression purposes.

0 was comparing equal to False. We expect text equality.
This commit is contained in:
Hans-Kristian Arntzen 2019-10-04 11:04:52 +02:00
parent 43e89bd269
commit 309e994224

View File

@ -438,30 +438,14 @@ def reference_path(directory, relpath, opt):
reference_dir = os.path.join(reference_dir, split_paths[1])
return os.path.join(reference_dir, relpath)
def json_ordered(obj):
if isinstance(obj, dict):
return sorted((k, json_ordered(v)) for k, v in obj.items())
if isinstance(obj, list):
return sorted(json_ordered(x) for x in obj)
else:
return obj
def json_compare(json_a, json_b):
return json_ordered(json_a) == json_ordered(json_b)
def regression_check_reflect(shader, json_file, args):
reference = reference_path(shader[0], shader[1], args.opt) + '.json'
joined_path = os.path.join(shader[0], shader[1])
print('Reference shader reflection path:', reference)
if os.path.exists(reference):
actual = ''
expected = ''
with open(json_file) as f:
actual_json = f.read();
actual = json.loads(actual_json)
with open(reference) as f:
expected = json.load(f)
if (json_compare(actual, expected) != True):
actual = md5_for_file(json_file)
expected = md5_for_file(reference)
if actual != expected:
if args.update:
print('Generated reflection json has changed for {}!'.format(reference))
# If we expect changes, update the reference file.