[game-data-packager] 24/51: check_equivalence: Assert that to_data(expand=False) yields same result
Simon McVittie
smcv at debian.org
Fri Dec 29 01:23:36 UTC 2017
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch master
in repository game-data-packager.
commit a5be9a894aea0afb8a00d3152f92bf82f72cbb69
Author: Simon McVittie <smcv at debian.org>
Date: Tue Dec 26 18:31:43 2017 +0000
check_equivalence: Assert that to_data(expand=False) yields same result
This will let us use it in make-template.
Signed-off-by: Simon McVittie <smcv at debian.org>
---
tools/check_equivalence.py | 35 ++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/tools/check_equivalence.py b/tools/check_equivalence.py
index a104dff..9ccf046 100755
--- a/tools/check_equivalence.py
+++ b/tools/check_equivalence.py
@@ -21,16 +21,16 @@ import os
import sys
import time
import yaml
+from contextlib import suppress
-from game_data_packager import load_games
+from game_data_packager import (load_games, load_game)
from game_data_packager.util import ascii_safe
def dump(serialized):
return json.dumps(serialized, sort_keys=True, indent=2)
def yaml_dump(serialized):
- return yaml.dump(
- serialized, default_flow_style=False)
+ return yaml.dump(serialized, default_flow_style=False)
def compare(
to_data, to_json, label,
@@ -101,6 +101,9 @@ if __name__ == '__main__':
for (name, game) in sorted(from_vfs.items()):
print('# %s -----------------------------------------' % name)
+ with suppress(FileNotFoundError):
+ os.remove('out/%s-unexpanded-yaml.txt' % name)
+
# Do this one without checking consistency, so that we can assert
# that skipping the consistency checks does not affect the outcome
game.load_file_data(check=False)
@@ -113,6 +116,8 @@ if __name__ == '__main__':
json_game.load_file_data(check=True, use_vfs=False)
json_to_data = json_game.to_data()
json_to_json = dump(json_to_data)
+ json_to_data_unexpanded = json_game.to_data(expand=False)
+ json_to_json_unexpanded = dump(json_to_data_unexpanded)
yaml_game = from_yaml[name]
yaml_game.load_file_data(check=True, datadir='data')
@@ -142,4 +147,28 @@ if __name__ == '__main__':
with open('out/%s-derived.txt' % name, 'w') as writer:
writer.write(vfs_to_json)
+ with open('out/%s-unexpanded.txt' % name, 'w') as writer:
+ writer.write(json_to_json_unexpanded)
+
+ json_to_json_games = {}
+ # JSON is a subset of YAML so we can treat this as if YAML
+ load_game(
+ False, json_to_json_games, 'out/%s-unexpanded.txt' % name,
+ None, name=name, yaml_file='out/%s-unexpanded.txt' % name)
+ json_to_json_game = json_to_json_games[name]
+ json_to_json_game.load_file_data()
+
+ json_to_json_to_data = json_to_json_game.to_data()
+ json_to_json_to_json = dump(json_to_json_to_data)
+
+ if not compare(
+ json_to_json_to_data, json_to_json_to_json,
+ '%s loaded from unexpanded YAML' % name,
+ vfs_to_data, vfs_to_json, '%s loaded from vfs.zip' % name):
+
+ with open('out/%s-unexpanded-yaml.txt' % name, 'w') as writer:
+ writer.write(yaml_dump(json_to_data_unexpanded))
+
+ fail = True
+
raise SystemExit(fail)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git
More information about the Pkg-games-commits
mailing list