|
13 | 13 | EXCLUDE_FILES = {'optional', 'refRemote.json', 'definitions.json'} |
14 | 14 | EXCLUDE_TESTS = { |
15 | 15 | # json-schema-org/JSON-Schema-Test-Suite#130 |
16 | | - ('ref.json', 'escaped pointer ref', 'percent invalid'), |
| 16 | +# ('ref.json', 'escaped pointer ref', 'percent invalid'), |
17 | 17 |
|
18 | 18 | # 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'), |
20 | 28 | } |
21 | 29 |
|
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) |
23 | 40 | failures = 0 |
24 | 41 |
|
25 | | -test_files = sys.argv[1:] |
26 | 42 | 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] |
28 | 44 |
|
29 | 45 | for test_file in test_files: |
30 | 46 | with open(test_file) as f: |
| 47 | + test_file = os.path.basename(test_file) |
31 | 48 | suites = json.load(f) |
32 | 49 | for suite in suites: |
33 | 50 | for test in suite['tests']: |
| 51 | + if (test_file, suite['description']) in EXCLUDE_TESTS: |
| 52 | + continue |
34 | 53 | if (test_file, suite['description'], test['description']) in EXCLUDE_TESTS: |
35 | 54 | continue |
36 | 55 |
|
| 56 | + command_args = ['SELECT validate_json_schema(json_schema_resolve_refs(%s), %s)', (json.dumps(suite['schema']), json.dumps(test['data']))] |
| 57 | + |
37 | 58 | 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)) |
39 | 61 | print('Failed: %s: %s. %s' % (suite['description'], test['description'], e)) |
40 | 62 | 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]) |
42 | 64 | except psycopg2.DataError as e: |
43 | 65 | fail(e) |
44 | 66 | failures += 1 |
| 67 | + except psycopg2.errors.StatementTooComplex as e: |
| 68 | + fail(e) |
| 69 | + exit(1) |
45 | 70 | else: |
46 | 71 | valid, = cur.fetchone() |
47 | 72 | if valid != test['valid']: |
|
0 commit comments