From df09dd064e86185349949f4bbc0e78e7fc833c3c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 30 Jan 2022 15:45:19 +0000 Subject: [PATCH] contrib/test-schema: Make this a little more useful * Can now supply only the Schema file name to test its loading, without needing to supply a test data file as well. * Added some status output, so it's more obvious when things worked. --- contrib/test-schema.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/contrib/test-schema.py b/contrib/test-schema.py index ebf0e51..da56adf 100644 --- a/contrib/test-schema.py +++ b/contrib/test-schema.py @@ -7,7 +7,7 @@ from jsonschema import validate as json_validate if len(sys.argv) < 2: print( f""" -Usage: {sys.argv[0]} +Usage: {sys.argv[0]} [] Note that the entire file will be loaded by simpljson.load() and should only contain one JSON object. @@ -16,12 +16,18 @@ only contain one JSON object. sys.exit(-1) schema_file_name = sys.argv[1] -test_file_name = sys.argv[2] +test_file_name = None +if len(sys.argv) == 3: + test_file_name = sys.argv[2] -with open(test_file_name, 'r') as test_file: - test_event = simplejson.load(test_file) +with open(schema_file_name, 'r') as schema_file: + schema = simplejson.load(schema_file) + print('Schema file loaded OK...') - with open(schema_file_name, 'r') as schema_file: - schema = simplejson.load(schema_file) + if test_file_name is not None: + with open(test_file_name, 'r') as test_file: + test_event = simplejson.load(test_file) - json_validate(test_event, schema, format_checker=FormatChecker()) + json_validate(test_event, schema, format_checker=FormatChecker()) + + print('Input file validated against schema OK.')