summaryrefslogtreecommitdiffstats
path: root/src/osmo_gsm_tester/log.py
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-04-09 22:01:16 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-04-09 22:01:16 +0200
commit85eb324165a8f4076fdd58f9d84b6c0443b5beb9 (patch)
treecb8da57dbaf55f463be4138c809b150e9f430635 /src/osmo_gsm_tester/log.py
parentb02c21115d1f2c76aa134ce7447998e9b26cc0b7 (diff)
make prematurely exited processes fail the test
Diffstat (limited to 'src/osmo_gsm_tester/log.py')
-rw-r--r--src/osmo_gsm_tester/log.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/osmo_gsm_tester/log.py b/src/osmo_gsm_tester/log.py
index 2ad82aa..a4f78df 100644
--- a/src/osmo_gsm_tester/log.py
+++ b/src/osmo_gsm_tester/log.py
@@ -48,6 +48,9 @@ DATEFMT = '%H:%M:%S'
# may be overridden by regression tests
get_process_id = lambda: '%d-%d' % (os.getpid(), time.time())
+class Error(Exception):
+ pass
+
class LogTarget:
do_log_time = None
do_log_category = None
@@ -166,13 +169,7 @@ class LogTarget:
else:
loglevel = ''
- log_line = [str(m) for m in messages]
-
- if named_items:
- # unfortunately needs to be sorted to get deterministic results
- log_line.append('{%s}' %
- (', '.join(['%s=%r' % (k,v)
- for k,v in sorted(named_items.items())])))
+ log_line = [compose_message(messages, named_items)]
if deeper_origins:
log_line.append(' [%s]' % deeper_origins)
@@ -316,6 +313,10 @@ class Origin:
Origin._global_current_origin, self._parent_origin = self._parent_origin, None
return rc
+ def raise_exn(self, *messages, exn_class=Error, **named_items):
+ with self:
+ raise exn_class(compose_message(messages, named_items))
+
def redirect_stdout(self):
return contextlib.redirect_stdout(SafeRedirectStdout(self))
@@ -498,4 +499,15 @@ def run_logging_exceptions(func, *func_args, return_on_failure=None, **func_kwar
log_exn()
return return_on_failure
+def compose_message(messages, named_items):
+ msgs = [str(m) for m in messages]
+
+ if named_items:
+ # unfortunately needs to be sorted to get deterministic results
+ msgs.append('{%s}' %
+ (', '.join(['%s=%r' % (k,v)
+ for k,v in sorted(named_items.items())])))
+
+ return ' '.join(msgs)
+
# vim: expandtab tabstop=4 shiftwidth=4