blob: 3cf27995e6d3aa05dfa81377fc585d81835a5e3c [file] [log] [blame]
Pau Espin Pedrol30637302020-05-06 21:11:02 +02001#!/usr/bin/env python3
2
3import _prep
4
5import sys
6import os
7import io
8import pprint
9import copy
10
11from osmo_gsm_tester.core import config, log, schema
12
13def val(which, test_schema):
14 try:
15 schema.validate(which, test_schema)
16 print('Validation: OK')
17 except ValueError:
18 log.log_exn()
19 print('Validation: Error')
20
21def get_case_list(dir):
22 li = []
23 for f in os.listdir(dir):
24 if f.startswith('schema_case'):
25 li.append(f)
26 return sorted(li)
27
28print('==== Testing dynamically generated schemas ====')
29for f in get_case_list(_prep.script_dir):
30 print('%s:' % f)
31 example_config = os.path.join(_prep.script_dir, f)
32 cfg = config.read(example_config)
33 try:
34 schema_def = schema.config_to_schema_def(cfg['schema'], 'foobar.prefix.')
35 except AssertionError:
36 schema_def = None
37 log.log_exn()
38 print('config2schema: Error')
39
40 if schema_def is not None:
41 pprint.pprint(schema_def)
42 i = 0
43 for t in cfg['tests']:
44 print('validating tests[%d]' % i)
45 val(t, schema_def)
46 i += 1
47 print('----------------------')
48
49
50
51
52
53# vim: expandtab tabstop=4 shiftwidth=4