Skip to content

Commit b8786ed

Browse files
committed
Change test to prefer a matching version instead of toolchain
1 parent a71d810 commit b8786ed

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

easybuild/framework/easyconfig/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ def find_related_easyconfigs(path, ec):
478478
parsed_version = LooseVersion(version).version
479479
version_patterns = [version] # exact version match
480480
if len(parsed_version) >= 2:
481-
version_patterns.append(r'%s\.%s\.\w+' % tuple(parsed_version[:2])) # major/minor version match
481+
version_patterns.append(r'%s\.%s(\.\w+|(?![\d.]))' % tuple(parsed_version[:2])) # major/minor version match
482482
if parsed_version != parsed_version[0]:
483-
version_patterns.append(r'%s\.[\d-]+(\.\w+)*' % parsed_version[0]) # major version match
483+
version_patterns.append(r'%s(\.[\d-]+(\.\w+)*|(?![\d.]))' % parsed_version[0]) # major version match
484484
version_patterns.append(r'[\w.]+') # any version
485485

486486
regexes = []

test/framework/easyconfig.py

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3390,40 +3390,67 @@ def test_find_related_easyconfigs(self):
33903390
res = [os.path.basename(x) for x in find_related_easyconfigs(test_easyconfigs, ec)]
33913391
self.assertEqual(res, ['toy-0.0-deps.eb'])
33923392

3393-
# Expected order:
3394-
# 1. Same toolchain & version
3395-
# 2. Same toolchain, different version
3396-
# 3. Any toolchain
3397-
# For each:
3398-
# exact version, major/minor version, major version, any version
33993393
ec['version'] = '1.2.3'
34003394
ec['toolchain'] = {'name': 'GCC', 'version': '12'}
34013395

3396+
# Create list of files in desired order, so we can remove them one by one
3397+
# to check that the search still finds the correct one.
3398+
# I.e. the file currently at the top should be returned,
3399+
# potentially with equally matching ones, given as values here.
3400+
#
3401+
# Expected order:
3402+
# 1. Same toolchain & version
3403+
# 2. Same toolchain, different version
3404+
# 3. Any toolchain
3405+
# Secondary criteria:
3406+
# a. Same toolchain incl. version
3407+
# b. Same toolchain, different version
3408+
# c. Different toolchain
3409+
testcases = {
3410+
# 1. Same version
3411+
'toy-1.2.3-GCC-12.eb': [],
3412+
'toy-1.2.3-GCC-11.eb': [],
3413+
'toy-1.2.3-Clang-12.eb': [],
3414+
# 2. Different or no patch version
3415+
'toy-1.2.0-GCC-12.eb': ['toy-1.2-GCC-12.eb'],
3416+
'toy-1.2-GCC-12.eb': [],
3417+
'toy-1.2.0-GCC-11.eb': ['toy-1.2-GCC-11.eb'],
3418+
'toy-1.2-GCC-11.eb': [],
3419+
'toy-1.2.0-Clang-12.eb': ['toy-1.2-Clang-12.eb'],
3420+
'toy-1.2-Clang-12.eb': [],
3421+
# 3. Different or no minor version, optional patch version
3422+
'toy-1.4.5-GCC-12.eb': ['toy-1.4-GCC-12.eb', 'toy-1-GCC-12.eb'],
3423+
'toy-1.4-GCC-12.eb': ['toy-1-GCC-12.eb'],
3424+
'toy-1-GCC-12.eb': [],
3425+
'toy-1.4.5-GCC-11.eb': ['toy-1.4-GCC-11.eb', 'toy-1-GCC-11.eb'],
3426+
'toy-1.4-GCC-11.eb': ['toy-1-GCC-11.eb'],
3427+
'toy-1-GCC-11.eb': [],
3428+
'toy-1.4.5-Clang-12.eb': ['toy-1.4-Clang-12.eb', 'toy-1-Clang-12.eb'],
3429+
'toy-1.4-Clang-12.eb': ['toy-1-Clang-12.eb'],
3430+
'toy-1-Clang-12.eb': [],
3431+
# 4 Different major version
3432+
'toy-4.2.3-GCC-12.eb': ['toy-4.2-GCC-12.eb', 'toy-4-GCC-12.eb'],
3433+
'toy-4.2-GCC-12.eb': ['toy-4-GCC-12.eb'],
3434+
'toy-4-GCC-12.eb': [],
3435+
'toy-4-GCC-11.eb': [],
3436+
'toy-4-Clang-12.eb': [],
3437+
}
3438+
34023439
# Use an empty folder to have full control over existing files
34033440
tmp_ec_dir = tempfile.mkdtemp()
34043441
files = []
3405-
# Create list of files in desired order,
3406-
# so we can remove them one by one to check that the search still finds the correct one
3407-
# 1. Same toolchain incl. version
3408-
# 2. Same toolchain, different version
3409-
# 3. Different toolchain
3410-
for toolchain in ('GCC-12', 'GCC-11', 'Clang-12'):
3411-
# Secondary criteria:
3412-
# a. Same version
3413-
# b. Same major.minor version
3414-
# c. Same major version
3415-
# d. Different version
3416-
for version in ('1.2.3', '1.2', '1', '4'):
3417-
filepath = os.path.join(tmp_ec_dir, '-'.join((ec['name'], version, toolchain)) + '.eb')
3418-
write_file(filepath, f"name = '{ec['name']}'")
3419-
files.append(filepath)
3442+
for filename in testcases:
3443+
filepath = os.path.join(tmp_ec_dir, filename)
3444+
write_file(filepath, f"name = '{ec['name']}'")
3445+
files.append(filepath)
34203446

34213447
ec_name = f'{ec.name}-{ec.version}-{ec["toolchain"]["name"]}-{ec["toolchain"]["version"]}'
34223448
while files:
34233449
result = find_related_easyconfigs(tmp_ec_dir, ec)
34243450
# Only show basenames in error
3425-
result, expected, files_b = [[os.path.basename(f) for f in cur_files]
3426-
for cur_files in (result, [files[0]], files)]
3451+
result, files_b = [[os.path.basename(f) for f in cur_files] for cur_files in (result, files)]
3452+
# first file in list should be the one found, followed by additional matches
3453+
expected = [files_b[0]] + testcases[files_b[0]]
34273454
self.assertEqual(result, expected,
34283455
msg='Found %s but expected %s when searching for "%s" in %s'
34293456
% (result, expected, ec_name, files_b))

0 commit comments

Comments
 (0)