Change in osmo-gsm-tester[master]: selftest: Introduce scenario_test

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Mon May 11 15:04:45 UTC 2020


pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18201 )

Change subject: selftest: Introduce scenario_test
......................................................................

selftest: Introduce scenario_test

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

Change-Id: I4c80047bb03ae8254c192057007fa7df84478605
---
A selftest/scenario_test/_prep.py
A selftest/scenario_test/paths.conf
A selftest/scenario_test/scenario_case_01.conf
A selftest/scenario_test/scenario_case_02.conf
A selftest/scenario_test/scenario_case_03 at .conf
A selftest/scenario_test/scenario_case_03 at specific.conf
A selftest/scenario_test/scenario_test.err
A selftest/scenario_test/scenario_test.ok
A selftest/scenario_test/scenario_test.ok.ign
A selftest/scenario_test/scenario_test.py
10 files changed, 178 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, approved



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 at .conf b/selftest/scenario_test/scenario_case_03 at .conf
new file mode 100644
index 0000000..d411191
--- /dev/null
+++ b/selftest/scenario_test/scenario_case_03 at .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 at specific.conf b/selftest/scenario_test/scenario_case_03 at specific.conf
new file mode 100644
index 0000000..925f908
--- /dev/null
+++ b/selftest/scenario_test/scenario_case_03 at 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 at .conf' (nor scenario_case_01 at .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 at heyho,1,yes.conf: DBG: {param_dict={param1='heyho', param2='1', param3='yes'}}
+scenario_case_03 at 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 at heyho,1,yes.conf: DBG: {param_dict={param1='heyho', param2='1', param3='yes'}}
+scenario_case_03 at 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 at 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 at 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 at specific.conf: DBG: {param_dict={param1='specific'}}
+scenario_case_03 at specific.conf
+{'somelist': [{'somelistitem': 'specific'}]}
+cnf -: DBG: Found path scenarios_dir as [PATH]/selftest/scenario_test
+tst scenario_case_03 at specific.conf: DBG: {param_dict={param1='specific'}}
+scenario_case_03 at 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 at heyho,1,yes', test_schema)
+
+#scenario 3 should fail due to missing parameters:
+try:
+    sc = scenario.get_scenario('scenario_case_03 at heyho,1', test_schema)
+except NameError as e:
+    print('OK: expected NameError: %s' % str(e))
+try:
+    sc = scenario.get_scenario('scenario_case_03 at 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 at specific', test_schema)
+
+# vim: expandtab tabstop=4 shiftwidth=4

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-gsm-tester/+/18201
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Change-Id: I4c80047bb03ae8254c192057007fa7df84478605
Gerrit-Change-Number: 18201
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200511/2be51649/attachment.htm>


More information about the gerrit-log mailing list