Skip to content

Commit 62998c8

Browse files
author
Vasileios Karakasis
committed
Treat properly deferrables
- As well as format `None` and errors in a human-readable manner.
1 parent 4bcd9fe commit 62998c8

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

reframe/core/logging.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ def _format_time_rfc3339(timestamp, datefmt):
165165

166166

167167
def _xfmt(val):
168+
from reframe.core.deferrable import _DeferredExpression
169+
170+
if val is None:
171+
return '<undefined>'
172+
173+
if isinstance(val, _DeferredExpression):
174+
try:
175+
return val.evaluate()
176+
except BaseException:
177+
return '<error>'
178+
168179
if isinstance(val, str):
169180
return val
170181

@@ -222,7 +233,7 @@ def formatTime(self, record, datefmt=None):
222233

223234
def format(self, record):
224235
datefmt = self.datefmt or self.default_time_format
225-
if record.check_job_completion_time_unix is not None:
236+
if record.check_job_completion_time_unix != _xfmt(None):
226237
ct = self.converter(record.check_job_completion_time_unix)
227238
record.check_job_completion_time = _format_time_rfc3339(
228239
ct, datefmt
@@ -437,21 +448,21 @@ def __init__(self, logger=None, check=None):
437448
# Here we only set the format specifiers that do not
438449
# correspond directly to check attributes
439450
'check': check,
440-
'check_jobid': '-1',
441-
'check_job_completion_time': None,
442-
'check_job_completion_time_unix': None,
451+
'check_jobid': _xfmt(None),
452+
'check_job_completion_time': _xfmt(None),
453+
'check_job_completion_time_unix': _xfmt(None),
443454
'check_info': 'reframe',
444-
'check_system': None,
445-
'check_partition': None,
446-
'check_environ': None,
447-
'check_perf_var': None,
448-
'check_perf_value': None,
449-
'check_perf_ref': None,
450-
'check_perf_lower_thres': None,
451-
'check_perf_upper_thres': None,
452-
'check_perf_unit': None,
453-
'osuser': osext.osuser() or '<unknown>',
454-
'osgroup': osext.osgroup() or '<unknown>',
455+
'check_system': _xfmt(None),
456+
'check_partition': _xfmt(None),
457+
'check_environ': _xfmt(None),
458+
'check_perf_var': _xfmt(None),
459+
'check_perf_value': _xfmt(None),
460+
'check_perf_ref': _xfmt(None),
461+
'check_perf_lower_thres': _xfmt(None),
462+
'check_perf_upper_thres': _xfmt(None),
463+
'check_perf_unit': _xfmt(None),
464+
'osuser': _xfmt(osext.osuser()),
465+
'osgroup': _xfmt(osext.osgroup()),
455466
'version': osext.reframe_version(),
456467
}
457468
)

unittests/test_logging.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import reframe.core.runtime as rt
2020
import reframe.core.settings as settings
2121
import reframe.utility as util
22+
import reframe.utility.sanity as sn
2223
from reframe.core.exceptions import ConfigError, ReframeError
2324
from reframe.core.backends import (getlauncher, getscheduler)
2425
from reframe.core.schedulers import Job
@@ -29,6 +30,10 @@ def fake_check():
2930
class _FakeCheck(rfm.RegressionTest):
3031
pass
3132

33+
@sn.sanity_function
34+
def error():
35+
raise BaseException
36+
3237
# A bit hacky, but we don't want to run a full test every time
3338
test = _FakeCheck()
3439
test._job = Job.create(getscheduler('local')(),
@@ -38,6 +43,8 @@ class _FakeCheck(rfm.RegressionTest):
3843
test.custom = 'hello extras'
3944
test.custom_list = ['custom', 'attr']
4045
test.custom_dict = {'a': 1, 'b': 2}
46+
test.deferred = sn.defer('hello')
47+
test.deferred_error = error()
4148
return test
4249

4350

@@ -156,10 +163,19 @@ def test_logger_dynamic_attributes(logfile, logger_with_check):
156163
logger_with_check.logger.handlers[0].setFormatter(formatter)
157164
logger_with_check.info('xxx')
158165
assert _pattern_in_logfile(
159-
r'hello extras\|custom,attr\|None\|a=1,b=2', logfile
166+
r'hello extras\|custom,attr\|<undefined>\|a=1,b=2', logfile
160167
)
161168

162169

170+
def test_logger_dynamic_attributes_deferrables(logfile, logger_with_check):
171+
formatter = rlog.RFC3339Formatter(
172+
'%(check_deferred)s|%(check_deferred_error)s'
173+
)
174+
logger_with_check.logger.handlers[0].setFormatter(formatter)
175+
logger_with_check.info('xxx')
176+
assert _pattern_in_logfile(r'hello\|<error>', logfile)
177+
178+
163179
def test_rfc3339_timezone_extension(logfile, logger_with_check,
164180
logger_without_check):
165181
formatter = rlog.RFC3339Formatter(

0 commit comments

Comments
 (0)