Change in ...osmo-gsm-tester[master]: suite_test: suite requires the fake trial to implement get_run_dir()

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
Thu Sep 19 13:44:57 UTC 2019


pespin has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/osmo-gsm-tester/+/15569 )

Change subject: suite_test: suite requires the fake trial to implement get_run_dir()
......................................................................

suite_test: suite requires the fake trial to implement get_run_dir()

If class Test calls get_run_dir(), it will generate the run dir from
Suite.get_run_dir() + append, and Suite.get_run_dir() in turn will do
the same with Trial.get_run_dir(). In suite_test.py, however, we are
passing a plain log.Origin object (parent of Trial), which doesn't
implement this function. We need to add it since tests will start using
get_run_dir() to write their own log files.

Generated tmp files are deleted on success and left there on error, in
order to be able to debug stuff easily.

Change-Id: Ic8326659a9ced0351e1e7e57ef21ce36f777729a
---
M selftest/suite_test.py
1 file changed, 24 insertions(+), 5 deletions(-)

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



diff --git a/selftest/suite_test.py b/selftest/suite_test.py
index db19ccc..115d76e 100755
--- a/selftest/suite_test.py
+++ b/selftest/suite_test.py
@@ -1,10 +1,26 @@
 #!/usr/bin/env python3
 import os
 import _prep
-from osmo_gsm_tester import log, suite, config, report
+import shutil
+from osmo_gsm_tester import log, suite, config, report, util
 
 config.ENV_CONF = './suite_test'
 
+example_trial_dir = os.path.join('test_trial_tmp')
+
+class FakeTrial(log.Origin):
+    def __init__(self):
+        super().__init__(log.C_TST, 'trial')
+        self.dir = util.Dir(example_trial_dir)
+        self._run_dir = None
+
+    def get_run_dir(self):
+        if self._run_dir is not None:
+            return self._run_dir
+        self._run_dir = util.Dir(self.dir.new_child('test_run'))
+        self._run_dir.mkdir()
+        return self._run_dir
+
 #log.style_change(trace=True)
 
 print('- non-existing suite dir')
@@ -20,7 +36,7 @@
 print(config.tostr(s_def.conf))
 
 print('- run hello world test')
-trial = log.Origin(log.C_TST, 'trial')
+trial = FakeTrial()
 s = suite.SuiteRun(trial, 'test_suite', s_def)
 results = s.run_tests('hello_world.py')
 print(report.suite_to_text(s))
@@ -43,7 +59,7 @@
 print(output)
 
 print('- test with half empty scenario')
-trial = log.Origin(log.C_TST, 'trial')
+trial = FakeTrial()
 scenario = config.Scenario('foo', 'bar')
 scenario['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] }
 s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
@@ -51,7 +67,7 @@
 print(report.suite_to_text(s))
 
 print('- test with scenario')
-trial = log.Origin(log.C_TST, 'trial')
+trial = FakeTrial()
 scenario = config.Scenario('foo', 'bar')
 scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] }
 s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
@@ -59,7 +75,7 @@
 print(report.suite_to_text(s))
 
 print('- test with scenario and modifiers')
-trial = log.Origin(log.C_TST, 'trial')
+trial = FakeTrial()
 scenario = config.Scenario('foo', 'bar')
 scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] }
 scenario['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': [{'nominal_power': '20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] }
@@ -70,4 +86,7 @@
 print(report.suite_to_text(s))
 
 print('\n- graceful exit.')
+#deleting generated tmp trial dir:
+shutil.rmtree(example_trial_dir, ignore_errors=True)
+
 # vim: expandtab tabstop=4 shiftwidth=4

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-gsm-tester/+/15569
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: Ic8326659a9ced0351e1e7e57ef21ce36f777729a
Gerrit-Change-Number: 15569
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/20190919/bbf2ef1c/attachment.htm>


More information about the gerrit-log mailing list