Skip to content

Commit ff33e20

Browse files
Merge branch 'master' into sanity_slurm_tests
2 parents 86a7ab6 + 9038050 commit ff33e20

File tree

9 files changed

+43
-33
lines changed

9 files changed

+43
-33
lines changed

reframe/core/pipeline.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
]
1414

1515

16-
import contextlib
1716
import functools
1817
import glob
1918
import inspect
@@ -211,7 +210,7 @@ def pipeline_hooks(cls):
211210
#: by this test.
212211
#:
213212
#: :type: :class:`List[str]`
214-
#: :default: ``None``
213+
#: :default: ``required``
215214
#:
216215
#: .. note::
217216
#: .. versionchanged:: 2.12
@@ -223,7 +222,9 @@ def pipeline_hooks(cls):
223222
#: .. versionchanged:: 3.3
224223
#: Default value changed from ``[]`` to ``None``.
225224
#:
226-
valid_prog_environs = variable(typ.List[str], type(None), value=None)
225+
#: .. versionchanged:: 3.6
226+
#: Default value changed from ``None`` to ``required``.
227+
valid_prog_environs = variable(typ.List[str])
227228

228229
#: List of systems supported by this test.
229230
#: The general syntax for systems is ``<sysname>[:<partname>]``.
@@ -236,13 +237,15 @@ def pipeline_hooks(cls):
236237
#: .. versionchanged:: 3.3
237238
#: Default value changed from ``[]`` to ``None``.
238239
#:
239-
valid_systems = variable(typ.List[str], type(None), value=None)
240+
#: .. versionchanged:: 3.6
241+
#: Default value changed from ``None`` to ``required``.
242+
valid_systems = variable(typ.List[str])
240243

241244
#: A detailed description of the test.
242245
#:
243246
#: :type: :class:`str`
244247
#: :default: ``self.name``
245-
descr = variable(str, type(None), value=None)
248+
descr = variable(str)
246249

247250
#: The path to the source file or source directory of the test.
248251
#:
@@ -337,7 +340,7 @@ def pipeline_hooks(cls):
337340
#:
338341
#: :type: :class:`str`
339342
#: :default: ``os.path.join('.', self.name)``
340-
executable = variable(str, type(None), value=None)
343+
executable = variable(str)
341344

342345
#: List of options to be passed to the :attr:`executable`.
343346
#:
@@ -586,25 +589,27 @@ def pipeline_hooks(cls):
586589
#: Refer to the :doc:`ReFrame Tutorials </tutorials>` for concrete usage
587590
#: examples.
588591
#:
589-
#: If set to :class:`None`, a sanity error will be raised during sanity
590-
#: checking.
592+
#: If not set a sanity error will be raised during sanity checking.
591593
#:
592594
#: :type: A deferrable expression (i.e., the result of a :doc:`sanity
593-
#: function </sanity_functions_reference>`) or :class:`None`
594-
#: :default: :class:`None`
595+
#: function </sanity_functions_reference>`)
596+
#: :default: :class:`required`
595597
#:
596598
#: .. note::
597599
#: .. versionchanged:: 2.9
598600
#: The default behaviour has changed and it is now considered a
599-
#: sanity failure if this attribute is set to :class:`None`.
601+
#: sanity failure if this attribute is set to :class:`required`.
600602
#:
601603
#: If a test doesn't care about its output, this must be stated
602604
#: explicitly as follows:
603605
#:
604606
#: ::
605607
#:
606608
#: self.sanity_patterns = sn.assert_true(1)
607-
sanity_patterns = variable(_DeferredExpression, type(None), value=None)
609+
#:
610+
#: .. versionchanged:: 3.6
611+
#: The default value has changed from ``None`` to ``required``.
612+
sanity_patterns = variable(_DeferredExpression)
608613

609614
#: Patterns for verifying the performance of this test.
610615
#:
@@ -829,14 +834,12 @@ def _rfm_init(self, name=None, prefix=None):
829834
self.name = name
830835

831836
# Pass if descr is a required variable.
832-
with contextlib.suppress(AttributeError):
833-
if self.descr is None:
834-
self.descr = self.name
837+
if not hasattr(self, 'descr'):
838+
self.descr = self.name
835839

836840
# Pass if the executable is a required variable.
837-
with contextlib.suppress(AttributeError):
838-
if self.executable is None:
839-
self.executable = os.path.join('.', self.name)
841+
if not hasattr(self, 'executable'):
842+
self.executable = os.path.join('.', self.name)
840843

841844
self._perfvalues = {}
842845

@@ -1520,11 +1523,11 @@ def check_sanity(self):
15201523
sn.assert_eq(self.job.exitcode, 0,
15211524
msg='job exited with exit code {0}')
15221525
]
1523-
if self.sanity_patterns is not None:
1526+
if hasattr(self, 'sanity_patterns'):
15241527
sanity_patterns.append(self.sanity_patterns)
15251528

15261529
self.sanity_patterns = sn.all(sanity_patterns)
1527-
elif self.sanity_patterns is None:
1530+
elif not hasattr(self, 'sanity_patterns'):
15281531
raise SanityError('sanity_patterns not set')
15291532

15301533
with osext.change_dir(self._stagedir):

reframe/frontend/loader.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ def _validate_check(self, check):
8181

8282
name = type(check).__name__
8383
checkfile = os.path.relpath(inspect.getfile(type(check)))
84-
required_attrs = ['sanity_patterns',
85-
'valid_systems', 'valid_prog_environs']
84+
required_attrs = ['valid_systems', 'valid_prog_environs']
8685
for attr in required_attrs:
87-
if getattr(check, attr) is None:
86+
if not hasattr(check, attr):
8887
getlogger().warning(
8988
f'{checkfile}: {attr!r} not defined for test {name!r}; '
9089
f'skipping...'

reframe/utility/osext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def run_command_async(cmd,
112112
return subprocess.Popen(args=cmd,
113113
stdout=stdout,
114114
stderr=stderr,
115+
stdin=subprocess.DEVNULL,
115116
universal_newlines=True,
116117
shell=shell,
117118
**popen_args)

unittests/resources/checks/bad/invalid_check.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
# SPDX-License-Identifier: BSD-3-Clause
55

66
import reframe as rfm
7-
import reframe.utility.sanity as sn
87

98

109
@rfm.simple_test
1110
class SomeTest(rfm.RegressionTest):
1211
def __init__(self):
1312
self.valid_systems = []
1413
self.valid_prog_environs = []
15-
self.sanity_patterns = sn.assert_true(1)
1614

1715

1816
class NotATest:

unittests/resources/checks/emptycheck.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
# SPDX-License-Identifier: BSD-3-Clause
55

66
import reframe as rfm
7-
import reframe.utility.sanity as sn
87

98

109
@rfm.simple_test
1110
class EmptyTest(rfm.RegressionTest):
1211
def __init__(self):
1312
self.valid_systems = []
1413
self.valid_prog_environs = []
15-
self.sanity_patterns = sn.assert_true(1)

unittests/resources/checks/frontend_checks.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ class TestWithGenerator(rfm.RunOnlyRegressionTest):
243243
def __init__(self):
244244
self.valid_systems = ['*']
245245
self.valid_prog_environs = ['*']
246-
self.sanity_patterns = sn.assert_true(1)
247246

248247
def foo():
249248
yield True
@@ -258,7 +257,6 @@ class TestWithFileObject(rfm.RunOnlyRegressionTest):
258257
def __init__(self):
259258
self.valid_systems = ['*']
260259
self.valid_prog_environs = ['*']
261-
self.sanity_patterns = sn.assert_true(1)
262260
with open(__file__) as fp:
263261
pass
264262

unittests/resources/checks_unlisted/good.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#
99

1010
import reframe as rfm
11-
import reframe.utility.sanity as sn
1211

1312
# We just import this individually for testing purposes
1413
from reframe.core.pipeline import RegressionTest
@@ -18,7 +17,6 @@ class _Base(RegressionTest):
1817
def __init__(self):
1918
self.valid_systems = ['*']
2019
self.valid_prog_environs = ['*']
21-
self.sanity_patterns = sn.assert_true(1)
2220

2321

2422
@rfm.parameterized_test(*((x, y) for x in range(3) for y in range(2)))

unittests/resources/checks_unlisted/kbd_interrupt.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#
1212

1313
import reframe as rfm
14-
import reframe.utility.sanity as sn
1514

1615

1716
@rfm.simple_test
@@ -22,7 +21,6 @@ def __init__(self):
2221
self.valid_systems = ['*']
2322
self.valid_prog_environs = ['*']
2423
self.tags = {self.name}
25-
self.sanity_patterns = sn.assert_true(1)
2624

2725
@rfm.run_before('setup')
2826
def raise_keyboard_interrupt(self):

unittests/test_pipeline.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,23 @@ def __init__(self):
240240
_run(MyTest(), *local_exec_ctx)
241241

242242

243+
def test_run_only_set_sanity_in_a_hook(local_exec_ctx):
244+
@fixtures.custom_prefix('unittests/resources/checks')
245+
class MyTest(rfm.RunOnlyRegressionTest):
246+
executable = './hello.sh'
247+
executable_opts = ['Hello, World!']
248+
local = True
249+
valid_prog_environs = ['*']
250+
valid_systems = ['*']
251+
252+
@rfm.run_after('run')
253+
def set_sanity(self):
254+
self.sanity_patterns = sn.assert_found(
255+
r'Hello, World\!', self.stdout)
256+
257+
_run(MyTest(), *local_exec_ctx)
258+
259+
243260
def test_run_only_no_srcdir(local_exec_ctx):
244261
@fixtures.custom_prefix('foo/bar/')
245262
class MyTest(rfm.RunOnlyRegressionTest):

0 commit comments

Comments
 (0)