From 7111bdbbbb7c95dfa91734c3eeffc5b3e984fcb1 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 2 Sep 2022 15:39:20 +0100 Subject: [PATCH] scripts/test-schema: A *very* basic script to see if a schema works * It's using `sys.argv`, not `argparse`. * Thus there's no `--help`. * Supply it with: 1) Filename of a schema definition, 2) filename of a full EDDN message text to test for compliance. * No output if both schema and message load *and* the message passes the schema. Else you'll get python exception output from `jsonschema.validate()`. --- scripts/test-schema.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 scripts/test-schema.py diff --git a/scripts/test-schema.py b/scripts/test-schema.py new file mode 100644 index 0000000..8df8617 --- /dev/null +++ b/scripts/test-schema.py @@ -0,0 +1,17 @@ +import sys + +import simplejson +import jsonschema + +schema_filename = sys.argv[1] +message_filename = sys.argv[2] + +schema_file = open(schema_filename, 'r') +schema_data = schema_file.read() +schema = simplejson.loads(schema_data) + +message_file = open(message_filename, 'r') +message_data = message_file.read() +message = simplejson.loads(message_data) + +jsonschema.validate(message, schema, format_checker=jsonschema.FormatChecker())