Pau Espin Pedrol | 0433c9b | 2020-05-11 16:52:16 +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 schema |
| 12 | from osmo_gsm_tester.core import config |
| 13 | from osmo_gsm_tester.core import scenario |
| 14 | |
| 15 | test_schema = { |
| 16 | 'somelist[].somelistitem': schema.STR, |
| 17 | 'anotherlist[]': schema.UINT, |
| 18 | 'foobar' : schema.BOOL_STR, |
| 19 | } |
| 20 | |
Pau Espin Pedrol | 6c6c0e8 | 2020-05-11 18:30:58 +0200 | [diff] [blame] | 21 | config.override_conf = os.path.join(os.path.dirname(sys.argv[0]), 'paths.conf') |
Pau Espin Pedrol | 0433c9b | 2020-05-11 16:52:16 +0200 | [diff] [blame] | 22 | |
| 23 | def print_scenario(sc): |
| 24 | # we use copy() to be able to get the dictionary in super class of Scenario: |
| 25 | pprint.pprint(sc) |
| 26 | pprint.pprint(sc.copy()) |
| 27 | |
| 28 | def load_scenario(name, sch=None): |
| 29 | # Test it loads the same both with .conf and without |
| 30 | sc = scenario.get_scenario(name, sch) |
| 31 | print_scenario(sc) |
| 32 | sc = scenario.get_scenario(name + '.conf', sch) |
| 33 | print_scenario(sc) |
| 34 | return sc |
| 35 | |
| 36 | # scenario case 01 should load fine |
| 37 | load_scenario('scenario_case_01', test_schema) |
| 38 | |
| 39 | # Try loading scenario 1 as if it was parametrized (but it's not): |
| 40 | try: |
| 41 | sc = scenario.get_scenario('scenario_case_01@', test_schema) |
| 42 | except RuntimeError as e: |
| 43 | print('OK: expected RuntimeError: %s' % str(e)) |
| 44 | |
| 45 | # scenario case 02 should fail to load, contains stuff not in test_schema |
| 46 | try: |
| 47 | sc = scenario.get_scenario('scenario_case_02', test_schema) |
| 48 | except ValueError as e: |
| 49 | print('OK: expected ValueError') |
| 50 | try: |
| 51 | sc = scenario.get_scenario('scenario_case_02.conf', test_schema) |
| 52 | except ValueError as e: |
| 53 | print('OK: expected ValueError') |
| 54 | |
| 55 | # scenario case 3 is parametrized, so loading without specifying so should fail: |
| 56 | try: |
| 57 | sc = scenario.get_scenario('scenario_case_03', test_schema) |
| 58 | except RuntimeError as e: |
| 59 | print('OK: expected RuntimeError: %s' % str(e)) |
| 60 | try: |
| 61 | sc = scenario.get_scenario('scenario_case_03.conf', test_schema) |
| 62 | except RuntimeError as e: |
| 63 | print('OK: expected RuntimeError: %s' % str(e)) |
| 64 | |
| 65 | #scenario 3 should load fine this way: |
| 66 | sc = load_scenario('scenario_case_03@heyho,1,yes', test_schema) |
| 67 | |
| 68 | #scenario 3 should fail due to missing parameters: |
| 69 | try: |
| 70 | sc = scenario.get_scenario('scenario_case_03@heyho,1', test_schema) |
| 71 | except NameError as e: |
| 72 | print('OK: expected NameError: %s' % str(e)) |
| 73 | try: |
| 74 | sc = scenario.get_scenario('scenario_case_03@heyho,1.conf', test_schema) |
| 75 | except NameError as e: |
| 76 | print('OK: expected NameError: %s' % str(e)) |
| 77 | |
| 78 | #scenario 3 should load the specific config file this way: |
| 79 | sc = load_scenario('scenario_case_03@specific', test_schema) |
| 80 | |
| 81 | # vim: expandtab tabstop=4 shiftwidth=4 |