mirror of
https://github.com/EDCD/EDDN.git
synced 2025-04-19 18:17:37 +03:00
Script for testing schemas
This commit is contained in:
parent
229ae1556a
commit
f8c1ce7a3e
27
contrib/test-schema.py
Normal file
27
contrib/test-schema.py
Normal file
@ -0,0 +1,27 @@
|
||||
"""Check if a file's JSON message passes the given schema."""
|
||||
import simplejson
|
||||
import sys
|
||||
from jsonschema import FormatChecker, ValidationError
|
||||
from jsonschema import validate as json_validate
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print(
|
||||
f"""
|
||||
Usage: {sys.argv[0]} <schema file name> <test data file name>
|
||||
|
||||
Note that the entire file will be loaded by simpljson.load() and should
|
||||
only contain one JSON object.
|
||||
"""
|
||||
)
|
||||
sys.exit(-1)
|
||||
|
||||
schema_file_name = sys.argv[1]
|
||||
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)
|
||||
|
||||
json_validate(test_event, schema, format_checker=FormatChecker())
|
Loading…
x
Reference in New Issue
Block a user