Skip to content

Commit 86ec6d0

Browse files
committed
Allow checksum+type in lists, tuples & dicts and disallow nested dicts
1 parent 6386772 commit 86ec6d0

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

easybuild/framework/easyconfig/types.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -622,18 +622,20 @@ def ensure_iterable_license_specs(specs):
622622

623623
# Type & value, value may be an int for type "size"
624624
# This is a bit too permissive as it allows the first element to be an int and doesn't restrict the number of elements
625-
CHECKSUM_TUPLE = (tuple, as_hashable({'elem_types': [str, int]}))
625+
CHECKSUM_AND_TYPE = (tuple, as_hashable({'elem_types': [str, int]}))
626+
CHECKSUM_LIST = (list, as_hashable({'elem_types': [str, CHECKSUM_AND_TYPE]}))
627+
CHECKSUM_TUPLE = (tuple, as_hashable({'elem_types': [str, CHECKSUM_AND_TYPE]}))
626628
CHECKSUM_DICT = (dict, as_hashable(
627629
{
628-
'elem_types': [type(None), str, CHECKSUM_TUPLE],
630+
'elem_types': [type(None), str, CHECKSUM_AND_TYPE, CHECKSUM_TUPLE, CHECKSUM_LIST],
629631
'key_types': [str],
630632
}
631633
))
632-
CHECKSUM_LIST = (list, as_hashable({'elem_types': [str, CHECKSUM_TUPLE, CHECKSUM_DICT]}))
633634

634-
CHECKSUMS = (list, as_hashable({'elem_types': [type(None), str, CHECKSUM_LIST, CHECKSUM_TUPLE, CHECKSUM_DICT]}))
635+
CHECKSUMS = (list, as_hashable({'elem_types': [type(None), str, CHECKSUM_AND_TYPE,
636+
CHECKSUM_LIST, CHECKSUM_TUPLE, CHECKSUM_DICT]}))
635637

636-
CHECKABLE_TYPES = [CHECKSUM_DICT, CHECKSUM_LIST, CHECKSUM_TUPLE, CHECKSUMS,
638+
CHECKABLE_TYPES = [CHECKSUM_AND_TYPE, CHECKSUM_LIST, CHECKSUM_TUPLE, CHECKSUM_DICT, CHECKSUMS,
637639
DEPENDENCIES, DEPENDENCY_DICT, LIST_OF_STRINGS,
638640
SANITY_CHECK_PATHS_DICT, SANITY_CHECK_PATHS_ENTRY, STRING_DICT, STRING_OR_TUPLE_LIST,
639641
STRING_OR_TUPLE_DICT, STRING_OR_TUPLE_OR_DICT_LIST, TOOLCHAIN_DICT, TUPLE_OF_STRINGS]

test/framework/type_checking.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ def test_check_type_of_param_value_sanity_check_paths(self):
174174
def test_check_type_of_param_value_checksums(self):
175175
"""Test check_type_of_param_value function for checksums."""
176176

177-
md5_checksum = 'fa618be8435447a017fd1bf2c7ae9224'
178-
sha256_checksum1 = 'fa618be8435447a017fd1bf2c7ae922d0428056cfc7449f7a8641edf76b48265'
179-
sha256_checksum2 = 'b5f9cb06105c1d2d30719db5ffb3ea67da60919fb68deaefa583deccd8813551'
180-
sha256_checksum3 = '033be54514a03e255df75c5aee8f9e672f663f93abb723444caec8fe43437bde'
177+
# Using (actually invalid) prefix to better detect those in case of errors
178+
md5_checksum = 'md518be8435447a017fd1bf2c7ae9224'
179+
sha256_checksum1 = 'sha18be8435447a017fd1bf2c7ae922d0428056cfc7449f7a8641edf76b48265'
180+
sha256_checksum2 = 'sha2cb06105c1d2d30719db5ffb3ea67da60919fb68deaefa583deccd8813551'
181+
sha256_checksum3 = 'sha3e54514a03e255df75c5aee8f9e672f663f93abb723444caec8fe43437bde'
182+
filesize = 45617379
181183

182184
# valid values for 'checksums' easyconfig parameters
183185
inputs = [
@@ -190,6 +192,7 @@ def test_check_type_of_param_value_checksums(self):
190192
# one checksum of specific type (as 2-tuple)
191193
[('md5', md5_checksum)],
192194
[('sha256', sha256_checksum1)],
195+
[('size', filesize)],
193196
# alternative checksums for a single file (n-tuple)
194197
[(sha256_checksum1, sha256_checksum2)],
195198
[(sha256_checksum1, sha256_checksum2, sha256_checksum3)],
@@ -213,17 +216,17 @@ def test_check_type_of_param_value_checksums(self):
213216
# two checksums for a single file, *both* should match
214217
[sha256_checksum1, md5_checksum],
215218
# three checksums for a single file, *all* should match
216-
[sha256_checksum1, ('md5', md5_checksum), {'foo.txt': sha256_checksum1}],
219+
[sha256_checksum1, ('md5', md5_checksum), ('size', filesize)],
217220
# single checksum for a single file
218221
sha256_checksum1,
219222
# filename-to-checksum mapping
220-
{'foo.txt': sha256_checksum1, 'bar.txt': sha256_checksum2},
223+
{'foo.txt': sha256_checksum1, 'bar.txt': sha256_checksum2, 'baz.txt': ('size', filesize)},
221224
# 3 alternative checksums for a single file, one match is sufficient
222225
(sha256_checksum1, sha256_checksum2, sha256_checksum3),
223226
# two alternative checksums for a single file (not to be confused by checksum-type & -value tuple)
224227
(sha256_checksum1, md5_checksum),
225228
# three alternative checksums for a single file of different types
226-
(sha256_checksum1, ('md5', md5_checksum), {'foo.txt': sha256_checksum1}),
229+
(sha256_checksum1, ('md5', md5_checksum), ('size', filesize)),
227230
# alternative checksums in dicts are also allowed
228231
{'foo.txt': (sha256_checksum2, sha256_checksum3), 'bar.txt': (sha256_checksum1, md5_checksum)},
229232
# Same but with lists -> all must match for each file

0 commit comments

Comments
 (0)