Skip to content

Commit 88f20d7

Browse files
committed
implement draft7 with absolute uris
1 parent 570e19f commit 88f20d7

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

JSON-Schema-Test-Suite

test.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,60 @@
1313
EXCLUDE_FILES = {'optional', 'refRemote.json', 'definitions.json'}
1414
EXCLUDE_TESTS = {
1515
# json-schema-org/JSON-Schema-Test-Suite#130
16-
('ref.json', 'escaped pointer ref', 'percent invalid'),
16+
# ('ref.json', 'escaped pointer ref', 'percent invalid'),
1717

1818
# json-schema-org/JSON-Schema-Test-Suite#114
19-
('ref.json', 'remote ref, containing refs itself', 'remote ref invalid'),
19+
('ref.json', 'remote ref, containing refs itself'),
20+
# ('id.json', 'id inside an enum is not a real identifier'),
21+
22+
# nul bytes are not supported by postgres
23+
('enum.json', 'nul characters in strings'),
24+
('const.json', 'nul characters in strings'),
25+
26+
# we are implementing like draft 2019 so we do include sibling props
27+
('ref.json', 'ref overrides any sibling keywords'),
2028
}
2129

22-
os.chdir('JSON-Schema-Test-Suite/tests/draft4')
30+
if '--dir' in sys.argv:
31+
idx = sys.argv.index('--dir')
32+
dir_name = sys.argv[idx+1]
33+
test_files = sys.argv[1:idx] + sys.argv[idx+2:]
34+
else:
35+
dir_name = 'JSON-Schema-Test-Suite/tests/draft4'
36+
test_files = sys.argv[1:]
37+
38+
print(f'switching to {dir_name} {sys.argv}')
39+
#os.chdir(dir_name)
2340
failures = 0
2441

25-
test_files = sys.argv[1:]
2642
if not test_files:
27-
test_files = [test_file for test_file in os.listdir('.') if test_file not in EXCLUDE_FILES]
43+
test_files = [os.path.join(dir_name, test_file) for test_file in os.listdir(dir_name) if test_file not in EXCLUDE_FILES]
2844

2945
for test_file in test_files:
3046
with open(test_file) as f:
47+
test_file = os.path.basename(test_file)
3148
suites = json.load(f)
3249
for suite in suites:
3350
for test in suite['tests']:
51+
if (test_file, suite['description']) in EXCLUDE_TESTS:
52+
continue
3453
if (test_file, suite['description'], test['description']) in EXCLUDE_TESTS:
3554
continue
3655

56+
command_args = ['SELECT validate_json_schema(json_schema_resolve_refs(%s), %s)', (json.dumps(suite['schema']), json.dumps(test['data']))]
57+
3758
def fail(e):
38-
print("%s: validate_json_schema('%s', '%s')" % (test_file, json.dumps(suite['schema']), json.dumps(test['data'])))
59+
cmd = command_args[0] % tuple("'%s'" % x for x in command_args[1])
60+
print("%s: %s" % (test_file, cmd))
3961
print('Failed: %s: %s. %s' % (suite['description'], test['description'], e))
4062
try:
41-
cur.execute('SELECT validate_json_schema(%s, %s)', (json.dumps(suite['schema']), json.dumps(test['data'])))
63+
cur.execute(command_args[0], command_args[1])
4264
except psycopg2.DataError as e:
4365
fail(e)
4466
failures += 1
67+
except psycopg2.errors.StatementTooComplex as e:
68+
fail(e)
69+
exit(1)
4570
else:
4671
valid, = cur.fetchone()
4772
if valid != test['valid']:

0 commit comments

Comments
 (0)