Give slightly more information when definition is invalid

Because it now fails at the assertion inside assertIsDefinitionValid, it'll show the information at that point in the stack, rather than showing that the entire function returned False which could be a lot of things (if you don't actually go reading the function because then you discovered that it could only be one thing).
This commit is contained in:
Ghostkeeper 2019-05-14 09:08:50 +02:00
parent c3efb666e8
commit 65bc29cd4c
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276

View file

@ -36,15 +36,14 @@ def test_validateMachineDefinitionContainer(file_name, definition_container):
return # Stop checking, these are root files.
definition_path = os.path.join(os.path.dirname(__file__), "..", "..", "resources", "definitions")
assert isDefinitionValid(definition_container, definition_path, file_name)
assertIsDefinitionValid(definition_container, definition_path, file_name)
def isDefinitionValid(definition_container, path, file_name):
def assertIsDefinitionValid(definition_container, path, file_name):
with open(os.path.join(path, file_name), encoding = "utf-8") as data:
json = data.read()
parser, is_valid = definition_container.readAndValidateSerialized(json)
if not is_valid:
print("The definition '{0}', has invalid data.".format(file_name))
assert is_valid #The definition has invalid JSON structure.
metadata = DefinitionContainer.deserializeMetadata(json, "whatever")
# If the definition defines a platform file, it should be in /resources/meshes/
@ -52,6 +51,4 @@ def isDefinitionValid(definition_container, path, file_name):
assert metadata[0]["platform"] in all_meshes
if "platform_texture" in metadata[0]:
assert metadata[0]["platform_texture"] in all_images
return is_valid
assert metadata[0]["platform_texture"] in all_images