blob: bffa601d4904a62f6ae222f48cedebcd2cc6b63c [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
Pau Espin Pedrold79e7192020-05-21 15:40:57 +020028def test_validator(val):
29 return val in ('valid_value1', 'valid_value2')
30
31schema.register_schema_types({'test_type': test_validator,
32 'another_type': lambda val: val == 'unique_val_ok'})
33
34
Pau Espin Pedrol30637302020-05-06 21:11:02 +020035print('==== Testing dynamically generated schemas ====')
36for f in get_case_list(_prep.script_dir):
37 print('%s:' % f)
38 example_config = os.path.join(_prep.script_dir, f)
39 cfg = config.read(example_config)
40 try:
41 schema_def = schema.config_to_schema_def(cfg['schema'], 'foobar.prefix.')
42 except AssertionError:
43 schema_def = None
44 log.log_exn()
45 print('config2schema: Error')
46
47 if schema_def is not None:
48 pprint.pprint(schema_def)
49 i = 0
50 for t in cfg['tests']:
51 print('validating tests[%d]' % i)
52 val(t, schema_def)
53 i += 1
54 print('----------------------')
55
56
57
58
59
60# vim: expandtab tabstop=4 shiftwidth=4