aboutsummaryrefslogtreecommitdiffstats
path: root/selftest
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-05-11 16:52:16 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2020-05-11 16:53:16 +0200
commit0433c9b6719539575474cd45ffd46fc5a5c947e2 (patch)
tree74fab93413d344a3dbecf132aaf46b79bc78b080 /selftest
parent4e6b5077d0df3220057c79631d24876d15ed2b83 (diff)
selftest: Introduce scenario_test
This covers some unit tests for scenario module (Scenario class). Change-Id: I4c80047bb03ae8254c192057007fa7df84478605
Diffstat (limited to 'selftest')
l---------selftest/scenario_test/_prep.py1
-rw-r--r--selftest/scenario_test/paths.conf3
-rw-r--r--selftest/scenario_test/scenario_case_01.conf10
-rw-r--r--selftest/scenario_test/scenario_case_02.conf11
-rw-r--r--selftest/scenario_test/scenario_case_03@.conf10
-rw-r--r--selftest/scenario_test/scenario_case_03@specific.conf2
-rw-r--r--selftest/scenario_test/scenario_test.err0
-rw-r--r--selftest/scenario_test/scenario_test.ok58
-rw-r--r--selftest/scenario_test/scenario_test.ok.ign2
-rwxr-xr-xselftest/scenario_test/scenario_test.py81
10 files changed, 178 insertions, 0 deletions
diff --git a/selftest/scenario_test/_prep.py b/selftest/scenario_test/_prep.py
new file mode 120000
index 0000000..9cea3fe
--- /dev/null
+++ b/selftest/scenario_test/_prep.py
@@ -0,0 +1 @@
+../_prep.py \ No newline at end of file
diff --git a/selftest/scenario_test/paths.conf b/selftest/scenario_test/paths.conf
new file mode 100644
index 0000000..c7df5ac
--- /dev/null
+++ b/selftest/scenario_test/paths.conf
@@ -0,0 +1,3 @@
+state_dir: ./test_work/state_dir
+suites_dir: .
+scenarios_dir: .
diff --git a/selftest/scenario_test/scenario_case_01.conf b/selftest/scenario_test/scenario_case_01.conf
new file mode 100644
index 0000000..1050a8d
--- /dev/null
+++ b/selftest/scenario_test/scenario_case_01.conf
@@ -0,0 +1,10 @@
+somelist:
+- somelistitem: 'firststring'
+- somelistitem: 'secondstring'
+- somelistitem: 'thirdstring'
+
+anotherlist:
+- 4
+- 0
+
+foobar: yes
diff --git a/selftest/scenario_test/scenario_case_02.conf b/selftest/scenario_test/scenario_case_02.conf
new file mode 100644
index 0000000..bf7b3d6
--- /dev/null
+++ b/selftest/scenario_test/scenario_case_02.conf
@@ -0,0 +1,11 @@
+somelist:
+- somelistitem: 'firststring'
+- somelistitem: 'secondstring'
+- somelistitem: 'thirdstring'
+
+anotherlist:
+- 4
+- 0
+
+foobar: yes
+unexpectedfoo: gonnafail
diff --git a/selftest/scenario_test/scenario_case_03@.conf b/selftest/scenario_test/scenario_case_03@.conf
new file mode 100644
index 0000000..d411191
--- /dev/null
+++ b/selftest/scenario_test/scenario_case_03@.conf
@@ -0,0 +1,10 @@
+somelist:
+- somelistitem: 'firststring'
+- somelistitem: ${param1}
+- somelistitem: 'thirdstring'
+
+anotherlist:
+- ${param2}
+- 0
+
+foobar: ${param3}
diff --git a/selftest/scenario_test/scenario_case_03@specific.conf b/selftest/scenario_test/scenario_case_03@specific.conf
new file mode 100644
index 0000000..925f908
--- /dev/null
+++ b/selftest/scenario_test/scenario_case_03@specific.conf
@@ -0,0 +1,2 @@
+somelist:
+- somelistitem: 'specific'
diff --git a/selftest/scenario_test/scenario_test.err b/selftest/scenario_test/scenario_test.err
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/selftest/scenario_test/scenario_test.err
diff --git a/selftest/scenario_test/scenario_test.ok b/selftest/scenario_test/scenario_test.ok
new file mode 100644
index 0000000..7fe2049
--- /dev/null
+++ b/selftest/scenario_test/scenario_test.ok
@@ -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'}]}
diff --git a/selftest/scenario_test/scenario_test.ok.ign b/selftest/scenario_test/scenario_test.ok.ign
new file mode 100644
index 0000000..a19fb8b
--- /dev/null
+++ b/selftest/scenario_test/scenario_test.ok.ign
@@ -0,0 +1,2 @@
+/[^ ]*/selftest/ [PATH]/selftest/
+\.py:[0-9]* .py:[LINENR]
diff --git a/selftest/scenario_test/scenario_test.py b/selftest/scenario_test/scenario_test.py
new file mode 100755
index 0000000..f5f42f7
--- /dev/null
+++ b/selftest/scenario_test/scenario_test.py
@@ -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