Skip to content

Commit 530982b

Browse files
authored
Merge pull request #4 from boegel/checksums-itemdict
fix type spec for checksums
2 parents d00921f + caef102 commit 530982b

2 files changed

Lines changed: 52 additions & 11 deletions

File tree

easybuild/framework/easyconfig/types.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,12 @@ def ensure_iterable_license_specs(specs):
514514
TUPLE_OF_STRINGS = (tuple, as_hashable({'elem_types': [str]}))
515515
LIST_OF_STRINGS = (list, as_hashable({'elem_types': [str]}))
516516
STRING_OR_TUPLE_LIST = (list, as_hashable({'elem_types': [str, TUPLE_OF_STRINGS]}))
517+
STRING_DICT = (dict, as_hashable(
518+
{
519+
'elem_types': [str],
520+
'key_types': [str],
521+
}
522+
))
517523
SANITY_CHECK_PATHS_DICT = (dict, as_hashable({
518524
'elem_types': {
519525
'files': [STRING_OR_TUPLE_LIST],
@@ -522,17 +528,16 @@ def ensure_iterable_license_specs(specs):
522528
'opt_keys': [],
523529
'req_keys': ['files', 'dirs'],
524530
}))
525-
CHECKSUM = (list, as_hashable({'elem_types': [str, TUPLE_OF_STRINGS]}))
526-
DICT_CHECKSUM = (dict, as_hashable(
527-
{
528-
'elem_types': [str, CHECKSUM],
529-
'key_types': [str],
530-
}
531-
))
532-
CHECKSUMS = (list, as_hashable({'elem_types': [CHECKSUM, DICT_CHECKSUM]}))
533-
534-
CHECKABLE_TYPES = [CHECKSUM, CHECKSUMS, DEPENDENCIES, DEPENDENCY_DICT, DICT_CHECKSUM, LIST_OF_STRINGS,
535-
SANITY_CHECK_PATHS_DICT, STRING_OR_TUPLE_LIST, TOOLCHAIN_DICT, TUPLE_OF_STRINGS]
531+
# checksums is a list of checksums, one entry per file (source/patch)
532+
# each entry can be:
533+
# a single checksum value (string)
534+
# a single checksum value of a specified type (2-tuple, 1st element is checksum type, 2nd element is checksum)
535+
# a list of checksums (of different types) as string values, which should *all* be valid
536+
# a dictionary with a mapping from filename to checksum value
537+
CHECKSUMS = (list, as_hashable({'elem_types': [str, tuple, LIST_OF_STRINGS, STRING_DICT]}))
538+
539+
CHECKABLE_TYPES = [CHECKSUMS, DEPENDENCIES, DEPENDENCY_DICT, LIST_OF_STRINGS,
540+
SANITY_CHECK_PATHS_DICT, STRING_DICT, STRING_OR_TUPLE_LIST, TOOLCHAIN_DICT, TUPLE_OF_STRINGS]
536541

537542
# easy types, that can be verified with isinstance
538543
EASY_TYPES = [basestring, bool, dict, int, list, str, tuple]

test/framework/type_checking.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,42 @@ def test_check_type_of_param_value_sanity_check_paths(self):
170170
out = {'files': ['bin/foo', ('bin/bar', 'bin/baz')], 'dirs': [('lib', 'lib64', 'lib32')]}
171171
self.assertEqual(check_type_of_param_value('sanity_check_paths', inp, auto_convert=True), (True, out))
172172

173+
def test_check_type_of_param_value_checksums(self):
174+
"""Test check_type_of_param_value function for checksums."""
175+
176+
md5_checksum = 'fa618be8435447a017fd1bf2c7ae9224'
177+
sha256_checksum1 = 'fa618be8435447a017fd1bf2c7ae922d0428056cfc7449f7a8641edf76b48265'
178+
sha256_checksum2 = 'b5f9cb06105c1d2d30719db5ffb3ea67da60919fb68deaefa583deccd8813551'
179+
sha256_checksum3 = '033be54514a03e255df75c5aee8f9e672f663f93abb723444caec8fe43437bde'
180+
181+
# valid values for 'checksums' easyconfig parameters
182+
inputs = [
183+
[],
184+
# single checksum (one file)
185+
[md5_checksum],
186+
[sha256_checksum1],
187+
# one checksum, for 3 files
188+
[sha256_checksum1, sha256_checksum2, sha256_checksum3],
189+
# one checksum of specific type
190+
[('md5', md5_checksum)],
191+
[('sha256', sha256_checksum1)],
192+
# multiple checksums of specific type, one for each file
193+
[('md5', md5_checksum), ('sha256', sha256_checksum1)],
194+
# checksum as dict (file to checksum mapping)
195+
[{'foo.txt': sha256_checksum1, 'bar.txt': sha256_checksum2}],
196+
# list of checksums for a single file
197+
[[md5_checksum]],
198+
[[sha256_checksum1, sha256_checksum2, sha256_checksum3]],
199+
# in the mix (3 files, each a different kind of checksum spec)...
200+
[
201+
sha256_checksum1,
202+
('md5', md5_checksum),
203+
{'foo.txt': sha256_checksum2, 'bar.txt': sha256_checksum3},
204+
],
205+
]
206+
for inp in inputs:
207+
self.assertEqual(check_type_of_param_value('checksums', inp), (True, inp))
208+
173209
def test_convert_value_type(self):
174210
"""Test convert_value_type function."""
175211
# to string

0 commit comments

Comments
 (0)