Pau Espin Pedrol | 3063730 | 2020-05-06 21:11:02 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import _prep |
| 4 | |
| 5 | import sys |
| 6 | import os |
| 7 | import io |
| 8 | import pprint |
| 9 | import copy |
| 10 | |
| 11 | from osmo_gsm_tester.core import config, log, schema |
| 12 | |
| 13 | def 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 | |
| 21 | def 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 | |
| 28 | print('==== Testing dynamically generated schemas ====') |
| 29 | for 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 |