aboutsummaryrefslogtreecommitdiffstats
path: root/selftest/scenario_test/scenario_test.py
blob: 15f8983cbb752ee6f296de1be7216e1ef78d86b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3

import _prep

import sys
import os
import io
import pprint
import copy

from osmo_gsm_tester.core import schema
from osmo_gsm_tester.core import config
from osmo_gsm_tester.core import scenario

test_schema = {
    'somelist[].somelistitem': schema.STR,
    'anotherlist[]': schema.UINT,
    'foobar' : schema.BOOL_STR,
    }

config.override_conf = os.path.join(os.path.dirname(sys.argv[0]), 'paths.conf')

def print_scenario(sc):
    # we use copy() to be able to get the dictionary in super class of Scenario:
    pprint.pprint(sc)
    pprint.pprint(sc.copy())

def load_scenario(name, sch=None):
    # Test it loads the same both with .conf and without
    sc = scenario.get_scenario(name, sch)
    print_scenario(sc)
    sc = scenario.get_scenario(name + '.conf', sch)
    print_scenario(sc)
    return sc

# scenario case 01 should load fine
load_scenario('scenario_case_01', test_schema)

# Try loading scenario 1 as if it was parametrized (but it's not):
try:
    sc = scenario.get_scenario('scenario_case_01@', test_schema)
except RuntimeError as e:
    print('OK: expected RuntimeError: %s' % str(e))

# scenario case 02 should fail to load, contains stuff not in test_schema
try:
    sc = scenario.get_scenario('scenario_case_02', test_schema)
except ValueError as e:
    print('OK: expected ValueError')
try:
    sc = scenario.get_scenario('scenario_case_02.conf', test_schema)
except ValueError as e:
    print('OK: expected ValueError')

# scenario case 3 is parametrized, so loading without specifying so should fail:
try:
    sc = scenario.get_scenario('scenario_case_03', test_schema)
except RuntimeError as e:
    print('OK: expected RuntimeError: %s' % str(e))
try:
    sc = scenario.get_scenario('scenario_case_03.conf', test_schema)
except RuntimeError as e:
    print('OK: expected RuntimeError: %s' % str(e))

#scenario 3 should load fine this way:
sc = load_scenario('scenario_case_03@heyho,1,yes', test_schema)

#scenario 3 should fail due to missing parameters:
try:
    sc = scenario.get_scenario('scenario_case_03@heyho,1', test_schema)
except NameError as e:
    print('OK: expected NameError: %s' % str(e))
try:
    sc = scenario.get_scenario('scenario_case_03@heyho,1.conf', test_schema)
except NameError as e:
    print('OK: expected NameError: %s' % str(e))

#scenario 3 should load the specific config file this way:
sc = load_scenario('scenario_case_03@specific', test_schema)

# vim: expandtab tabstop=4 shiftwidth=4