blob: 15f8983cbb752ee6f296de1be7216e1ef78d86b4 [file] [log] [blame]
Pau Espin Pedrol0433c9b2020-05-11 16:52:16 +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 schema
12from osmo_gsm_tester.core import config
13from osmo_gsm_tester.core import scenario
14
15test_schema = {
16 'somelist[].somelistitem': schema.STR,
17 'anotherlist[]': schema.UINT,
18 'foobar' : schema.BOOL_STR,
19 }
20
Pau Espin Pedrol6c6c0e82020-05-11 18:30:58 +020021config.override_conf = os.path.join(os.path.dirname(sys.argv[0]), 'paths.conf')
Pau Espin Pedrol0433c9b2020-05-11 16:52:16 +020022
23def 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
28def 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
37load_scenario('scenario_case_01', test_schema)
38
39# Try loading scenario 1 as if it was parametrized (but it's not):
40try:
41 sc = scenario.get_scenario('scenario_case_01@', test_schema)
42except 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
46try:
47 sc = scenario.get_scenario('scenario_case_02', test_schema)
48except ValueError as e:
49 print('OK: expected ValueError')
50try:
51 sc = scenario.get_scenario('scenario_case_02.conf', test_schema)
52except ValueError as e:
53 print('OK: expected ValueError')
54
55# scenario case 3 is parametrized, so loading without specifying so should fail:
56try:
57 sc = scenario.get_scenario('scenario_case_03', test_schema)
58except RuntimeError as e:
59 print('OK: expected RuntimeError: %s' % str(e))
60try:
61 sc = scenario.get_scenario('scenario_case_03.conf', test_schema)
62except RuntimeError as e:
63 print('OK: expected RuntimeError: %s' % str(e))
64
65#scenario 3 should load fine this way:
66sc = load_scenario('scenario_case_03@heyho,1,yes', test_schema)
67
68#scenario 3 should fail due to missing parameters:
69try:
70 sc = scenario.get_scenario('scenario_case_03@heyho,1', test_schema)
71except NameError as e:
72 print('OK: expected NameError: %s' % str(e))
73try:
74 sc = scenario.get_scenario('scenario_case_03@heyho,1.conf', test_schema)
75except NameError as e:
76 print('OK: expected NameError: %s' % str(e))
77
78#scenario 3 should load the specific config file this way:
79sc = load_scenario('scenario_case_03@specific', test_schema)
80
81# vim: expandtab tabstop=4 shiftwidth=4