Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/slurm-hyphen-constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarak authored Dec 6, 2024
2 parents 03ce00a + 3dafd84 commit b7e1e3f
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/manpage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ The way the tests are generated and how they interact with the test filtering op

Parameterize a test on an existing variable.

This option will create a new test with a parameter named ``$VAR`` with the values given in the comma-separated list ``VAL0,VAL1,...``.
The test will behave as if the variable ``VAR`` was a parameter taking the values ``VAL0,VAL1,...``.
The values will be converted based on the type of the target variable ``VAR``.
The ``TEST.`` prefix will only parameterize the variable ``VAR`` of test ``TEST``.

Expand Down
4 changes: 3 additions & 1 deletion reframe/core/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,9 @@ def _resolve_fixtures(self):
# registered under the same fixture class. So the loop below must
# also inspect the fixture data the instance was registered with.
for fixt_name, fixt_data in registry[f.cls].items():
if f.scope != fixt_data.scope:
if fixt_data.variables != f.variables:
continue
elif f.scope != fixt_data.scope:
continue
elif fixt_data.variant_num not in target_variants:
continue
Expand Down
3 changes: 2 additions & 1 deletion reframe/frontend/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,8 @@ def restrict_logging():
with exit_gracefully_on_error('failed to retrieve test case data',
printer):
printer.info(jsonext.dumps(reporting.testcase_info(
options.describe_stored_testcases, namepatt
options.describe_stored_testcases,
namepatt, options.filter_expr
), indent=2))
sys.exit(0)

Expand Down
32 changes: 23 additions & 9 deletions reframe/frontend/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,31 @@ def load_from_file(self, filename, force=False):

try:
dirname = os.path.dirname(filename)
with osext.change_dir(dirname):
with util.temp_sys_path(dirname):
if os.path.exists(os.path.join(dirname, '__init__.py')):
# If the containing directory is a package,
# import it, too.
parent = util.import_module_from_file(dirname).__name__
else:
parent = None

# Load all parent modules of test file
parents = []
while os.path.exists(os.path.join(dirname, '__init__.py')):
parents.append(os.path.join(dirname))
dirname = os.path.split(dirname)[0]

parent_module = None
for pdir in reversed(parents):
with osext.change_dir(pdir):
with util.temp_sys_path(pdir):
package_path = os.path.join(pdir, '__init__.py')
parent_module = util.import_module_from_file(
package_path, parent=parent_module
).__name__

# Now load the actual test file
if not parents:
pdir = dirname

with osext.change_dir(pdir):
with util.temp_sys_path(pdir):
return self.load_from_module(
util.import_module_from_file(filename, force, parent)
util.import_module_from_file(filename, force,
parent_module)
)
except Exception:
exc_info = sys.exc_info()
Expand Down
16 changes: 8 additions & 8 deletions reframe/frontend/testgenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def _generate_tests(testcases, gen_fn):
@time_function
def distribute_tests(testcases, node_map):
def _rfm_pin_run_nodes(obj):
nodelist = getattr(obj, '$nid')
nodelist = getattr(obj, '.nid')
if not obj.local:
obj.job.pin_nodes = nodelist

def _rfm_pin_build_nodes(obj):
pin_nodes = getattr(obj, '$nid')
pin_nodes = getattr(obj, '.nid')
if obj.build_job and not obj.local and not obj.build_locally:
obj.build_job.pin_nodes = pin_nodes

Expand All @@ -99,9 +99,9 @@ def _rfm_set_valid_systems(obj):
'valid_systems': [partition.fullname],
# We add a partition parameter so as to differentiate the test
# in case another test has the same nodes in another partition
'$part': builtins.parameter([partition.fullname],
'.part': builtins.parameter([partition.fullname],
loggable=False),
'$nid': builtins.parameter(
'.nid': builtins.parameter(
[[n] for n in node_map[partition.fullname]],
fmt=util.nodelist_abbrev, loggable=False
)
Expand All @@ -113,7 +113,7 @@ def _rfm_set_valid_systems(obj):
# will not be overwritten by a parent post-init hook
builtins.run_after('init')(_rfm_set_valid_systems),
]
), ['$part', '$nid']
), ['.part', '.nid']

return _generate_tests(testcases, _make_dist_test)

Expand All @@ -127,10 +127,10 @@ def _make_repeat_test(testcase):
return make_test(
cls.__name__, (cls,),
{
'$repeat_no': builtins.parameter(range(num_repeats),
'.repeat_no': builtins.parameter(range(num_repeats),
loggable=False)
}
), ['$repeat_no']
), ['.repeat_no']

return _generate_tests(testcases, _make_repeat_test)

Expand Down Expand Up @@ -164,7 +164,7 @@ def _make_parameterized_test(testcase):
)
continue

body[f'${var}'] = builtins.parameter(values, loggable=False)
body[f'.{var}'] = builtins.parameter(values, loggable=False)

def _set_vars(self):
for var in body.keys():
Expand Down
2 changes: 1 addition & 1 deletion reframe/utility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ def count_digits(n):
'''

num_digits = 1
while n > 10:
while n >= 10:
n /= 10
num_digits += 1

Expand Down
14 changes: 14 additions & 0 deletions unittests/resources/checks_unlisted/fixtures_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,17 @@ def validate_fixture_resolution(self):
ParamFixture.num_variants
)
])


@rfm.simple_test
class TestC(rfm.RunOnlyRegressionTest):
valid_systems = ['*']
valid_prog_environs = ['*']
executable = 'echo'
f0 = fixture(SimpleFixture, scope='environment', variables={'data': 10})
f1 = fixture(SimpleFixture, scope='environment', variables={'data': 20})

@sanity_function
def validate_vars(self):
return sn.all([sn.assert_eq(self.f0.data, 10),
sn.assert_eq(self.f1.data, 20)])
Empty file.
17 changes: 17 additions & 0 deletions unittests/resources/checks_unlisted/testlib/nested/dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2016-2024 Swiss National Supercomputing Centre (CSCS/ETH Zurich)
# ReFrame Project Developers. See the top-level LICENSE file for details.
#
# SPDX-License-Identifier: BSD-3-Clause

import reframe as rfm
import reframe.utility.sanity as sn
from ..utility import dummy_fixture


@rfm.simple_test
class dummy_test(rfm.RunOnlyRegressionTest):
valid_systems = ['*']
valid_prog_environs = ['*']
executable = 'true'
sanity_patterns = sn.assert_true(1)
dummy = fixture(dummy_fixture)
2 changes: 1 addition & 1 deletion unittests/resources/checks_unlisted/testlib/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class simple_echo_check(rfm.RunOnlyRegressionTest, pin_prefix=True):
executable = 'echo'
executable_opts = ['Hello']
message = variable(str, value='World')
dummy = fixture(dummy_fixture, scope='environment')
dummy = fixture(dummy_fixture)

@run_before('run')
def set_executable_opts(self):
Expand Down
2 changes: 1 addition & 1 deletion unittests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ def test_testlib_inherit_fixture_in_different_files(run_reframe):
action='run',
)
assert returncode == 0
assert 'Ran 3/3 test case(s)' in stdout
assert 'Ran 4/4 test case(s)' in stdout
assert 'FAILED' not in stdout


Expand Down
6 changes: 6 additions & 0 deletions unittests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,9 @@ def test_relative_import_outside_rfm_prefix(loader, tmp_path):
)
tests = loader.load_from_file(str(tmp_path / 'testlib' / 'simple.py'))
assert len(tests) == 2

# Test nested library tests
tests = loader.load_from_file(
str(tmp_path / 'testlib' / 'nested' / 'dummy.py')
)
assert len(tests) == 2
2 changes: 1 addition & 1 deletion unittests/test_testgenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def sys0p0_nodes():

nodelist_iter = sys0p0_nodes()
for tc in new_cases:
nodes = getattr(tc.check, '$nid')
nodes = getattr(tc.check, '.nid')
if tc.partition.fullname == 'sys0:p0':
assert nodes == next(nodelist_iter)
else:
Expand Down
8 changes: 8 additions & 0 deletions unittests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,14 @@ def test_nodelist_utilities():
assert nodelist(nodes) == 'nid0[00-99]-x,nid100-y'
assert expand('nid0[00-99]-x,nid100-y') == nodes

# Test edge condition when node lists jump from N to N+1 digits
# See GH issue #3338
nodes = ['vs-std-0009', 'vs-std-0010', 'vs-std-0099', 'vs-std-0100']
assert nodelist(nodes) == 'vs-std-00[09-10],vs-std-0[099-100]'
assert expand('vs-std-00[09-10],vs-std-0[099-100]') == [
'vs-std-0009', 'vs-std-0010', 'vs-std-0099', 'vs-std-0100'
]

# Test node duplicates
assert nodelist(['nid001', 'nid001', 'nid002']) == 'nid001,nid00[1-2]'
assert expand('nid001,nid00[1-2]') == ['nid001', 'nid001', 'nid002']
Expand Down

0 comments on commit b7e1e3f

Please sign in to comment.