selftest: Introduce scenario_test

This covers some unit tests for scenario module (Scenario class).

Change-Id: I4c80047bb03ae8254c192057007fa7df84478605
This commit is contained in:
Pau Espin 2020-05-11 16:52:16 +02:00
parent 4e6b5077d0
commit 0433c9b671
10 changed files with 178 additions and 0 deletions

View File

@ -0,0 +1 @@
../_prep.py

View File

@ -0,0 +1,3 @@
state_dir: ./test_work/state_dir
suites_dir: .
scenarios_dir: .

View File

@ -0,0 +1,10 @@
somelist:
- somelistitem: 'firststring'
- somelistitem: 'secondstring'
- somelistitem: 'thirdstring'
anotherlist:
- 4
- 0
foobar: yes

View File

@ -0,0 +1,11 @@
somelist:
- somelistitem: 'firststring'
- somelistitem: 'secondstring'
- somelistitem: 'thirdstring'
anotherlist:
- 4
- 0
foobar: yes
unexpectedfoo: gonnafail

View File

@ -0,0 +1,10 @@
somelist:
- somelistitem: 'firststring'
- somelistitem: ${param1}
- somelistitem: 'thirdstring'
anotherlist:
- ${param2}
- 0
foobar: ${param3}

View File

@ -0,0 +1,2 @@
somelist:
- somelistitem: 'specific'

View File

View File

@ -0,0 +1,58 @@
cnf -: DBG: Found config file paths.conf as [PATH]/selftest/scenario_test/paths.conf in [PATH]/selftest/scenario_test which is [PATH]/selftest/scenario_test
cnf -: DBG: [PATH]/selftest/scenario_test/paths.conf: relative path . is [PATH]/selftest/scenario_test
cnf -: DBG: [PATH]/selftest/scenario_test/paths.conf: relative path ./test_work/state_dir is [PATH]/selftest/scenario_test/test_work/state_dir
cnf -: DBG: [PATH]/selftest/scenario_test/paths.conf: relative path . is [PATH]/selftest/scenario_test
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
scenario_case_01.conf
{'anotherlist': ['4', '0'],
'foobar': 'True',
'somelist': [{'somelistitem': 'firststring'},
{'somelistitem': 'secondstring'},
{'somelistitem': 'thirdstring'}]}
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
scenario_case_01.conf
{'anotherlist': ['4', '0'],
'foobar': 'True',
'somelist': [{'somelistitem': 'firststring'},
{'somelistitem': 'secondstring'},
{'somelistitem': 'thirdstring'}]}
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
OK: expected RuntimeError: No such scenario file: '[PATH]/selftest/scenario_test/scenario_case_01@.conf' (nor scenario_case_01@.conf)
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
OK: expected ValueError
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
OK: expected ValueError
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
OK: expected RuntimeError: No such scenario file: '[PATH]/selftest/scenario_test/scenario_case_03.conf'
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
OK: expected RuntimeError: No such scenario file: '[PATH]/selftest/scenario_test/scenario_case_03.conf'
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
tst scenario_case_03@heyho,1,yes.conf: DBG: {param_dict={param1='heyho', param2='1', param3='yes'}}
scenario_case_03@heyho,1,yes.conf
{'anotherlist': ['1', '0'],
'foobar': 'True',
'somelist': [{'somelistitem': 'firststring'},
{'somelistitem': 'heyho'},
{'somelistitem': 'thirdstring'}]}
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
tst scenario_case_03@heyho,1,yes.conf: DBG: {param_dict={param1='heyho', param2='1', param3='yes'}}
scenario_case_03@heyho,1,yes.conf
{'anotherlist': ['1', '0'],
'foobar': 'True',
'somelist': [{'somelistitem': 'firststring'},
{'somelistitem': 'heyho'},
{'somelistitem': 'thirdstring'}]}
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
tst scenario_case_03@heyho,1.conf: DBG: {param_dict={param1='heyho', param2='1'}}
OK: expected NameError: Undefined
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
tst scenario_case_03@heyho,1.conf: DBG: {param_dict={param1='heyho', param2='1'}}
OK: expected NameError: Undefined
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
tst scenario_case_03@specific.conf: DBG: {param_dict={param1='specific'}}
scenario_case_03@specific.conf
{'somelist': [{'somelistitem': 'specific'}]}
cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
tst scenario_case_03@specific.conf: DBG: {param_dict={param1='specific'}}
scenario_case_03@specific.conf
{'somelist': [{'somelistitem': 'specific'}]}

View File

@ -0,0 +1,2 @@
/[^ ]*/selftest/ [PATH]/selftest/
\.py:[0-9]* .py:[LINENR]

View File

@ -0,0 +1,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]))
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