Skip to content

Commit 067a557

Browse files
author
Vasileios Karakasis
authored
Merge pull request #1185 from victorusu/feature/no-src-dir-runonlytest
[feat] Set default value of `sourcesdir` to `'src'` only if such a directory exists, otherwise set to `None`
2 parents 423320e + 62d62e5 commit 067a557

File tree

3 files changed

+177
-124
lines changed

3 files changed

+177
-124
lines changed

reframe/core/pipeline.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ class RegressionTest(metaclass=RegressionTestMeta):
202202
#: taken.
203203
#:
204204
#: :type: :class:`str` or :class:`None`
205-
#: :default: ``'src'``
205+
#: :default: ``'src'`` if such a directory exists at the test level,
206+
#: otherwise ``None``
206207
#:
207208
#: .. note::
208209
#: .. versionchanged:: 2.9
@@ -211,6 +212,10 @@ class RegressionTest(metaclass=RegressionTestMeta):
211212
#:
212213
#: .. versionchanged:: 2.10
213214
#: Support for Git repositories was added.
215+
#:
216+
#: .. versionchanged:: 3.0
217+
#: Default value is now conditionally set to either ``'src'`` or
218+
#: :class:`None`.
214219
sourcesdir = fields.TypedField('sourcesdir', str, type(None))
215220

216221
#: The build system to be used for this test.
@@ -661,8 +666,13 @@ def __new__(cls, *args, **kwargs):
661666
itertools.chain(args, kwargs.values()))
662667
name += '_' + '_'.join(arg_names)
663668

664-
obj._rfm_init(name,
665-
os.path.abspath(os.path.dirname(inspect.getfile(cls))))
669+
# Determine the prefix
670+
try:
671+
prefix = cls._rfm_custom_prefix
672+
except AttributeError:
673+
prefix = os.path.abspath(os.path.dirname(inspect.getfile(cls)))
674+
675+
obj._rfm_init(name, prefix)
666676
return obj
667677

668678
def __init__(self):
@@ -706,10 +716,11 @@ def _rfm_init(self, name=None, prefix=None):
706716
self.local = False
707717

708718
# Static directories of the regression check
709-
if prefix is not None:
710-
self._prefix = os.path.abspath(prefix)
711-
712-
self.sourcesdir = 'src'
719+
self._prefix = os.path.abspath(prefix)
720+
if os.path.isdir(os.path.join(self._prefix, 'src')):
721+
self.sourcesdir = 'src'
722+
else:
723+
self.sourcesdir = None
713724

714725
# Output patterns
715726
self.sanity_patterns = None

unittests/fixtures.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,16 @@ def partition_with_scheduler(name=None, skip_partitions=['kesch:pn']):
8686
def has_sane_modules_system():
8787
return not isinstance(rt.runtime().modules_system.backend,
8888
modules.NoModImpl)
89+
90+
91+
def custom_prefix(prefix):
92+
'''Assign a custom prefix to a test.
93+
94+
This is useful in unit tests when we want to create tests on-the-fly and
95+
associate them with existing resources.'''
96+
97+
def _set_prefix(cls):
98+
cls._rfm_custom_prefix = prefix
99+
return cls
100+
101+
return _set_prefix

0 commit comments

Comments
 (0)