|
37 | 37 | from easybuild.framework.easyconfig.types import LIST_OF_STRINGS, SANITY_CHECK_PATHS_DICT, STRING_OR_TUPLE_LIST |
38 | 38 | from easybuild.framework.easyconfig.types import TOOLCHAIN_DICT |
39 | 39 | from easybuild.framework.easyconfig.types import is_value_of_type, to_checksums, to_dependencies, to_dependency |
40 | | -from easybuild.framework.easyconfig.types import to_list_of_strings, to_list_of_strings_and_tuples, to_toolchain_dict |
41 | | -from easybuild.framework.easyconfig.types import to_sanity_check_paths_dict |
| 40 | +from easybuild.framework.easyconfig.types import to_list_of_strings, to_list_of_strings_and_tuples |
| 41 | +from easybuild.framework.easyconfig.types import to_list_of_strings_and_tuples_and_dicts |
| 42 | +from easybuild.framework.easyconfig.types import to_sanity_check_paths_dict, to_toolchain_dict |
42 | 43 | from easybuild.tools.build_log import EasyBuildError |
43 | 44 | from easybuild.tools.py2vs3 import string_type |
44 | 45 |
|
@@ -225,6 +226,25 @@ def test_check_type_of_param_value_checksums(self): |
225 | 226 | for inp in inputs: |
226 | 227 | self.assertEqual(check_type_of_param_value('checksums', inp), (True, inp)) |
227 | 228 |
|
| 229 | + def test_check_type_of_param_value_patches(self): |
| 230 | + """Test check_type_of_param_value function for patches.""" |
| 231 | + |
| 232 | + # patches values that do not need to be converted |
| 233 | + inputs = ( |
| 234 | + [], # empty list of patches |
| 235 | + # single patch, different types |
| 236 | + ['foo.patch'], # only filename |
| 237 | + [('foo.patch', '1')], # filename + patch level |
| 238 | + [('foo.patch', 'subdir')], # filename + subdir to apply patch in |
| 239 | + [{'name': 'foo.patch', 'level': '1'}], # filename + patch level, as dict value |
| 240 | + # multiple patches, mix of different types |
| 241 | + ['1.patch', '2.patch', '3.patch'], |
| 242 | + ['1.patch', ('2.patch', '2'), {'name': '3.patch'}], |
| 243 | + ['1.patch', {'name': '2.patch', 'level': '2'}, ('3.patch', '3')], |
| 244 | + ) |
| 245 | + for inp in inputs: |
| 246 | + self.assertEqual(check_type_of_param_value('patches', inp), (True, inp)) |
| 247 | + |
228 | 248 | def test_convert_value_type(self): |
229 | 249 | """Test convert_value_type function.""" |
230 | 250 | # to string |
@@ -614,11 +634,47 @@ def test_to_list_of_strings_and_tuples(self): |
614 | 634 | self.assertEqual(to_list_of_strings_and_tuples(('foo', ['bar', 'baz'])), ['foo', ('bar', 'baz')]) |
615 | 635 |
|
616 | 636 | # conversion failures |
617 | | - self.assertErrorRegex(EasyBuildError, "Expected value to be a list", to_list_of_strings_and_tuples, 'foo') |
| 637 | + error_regex = "Expected value to be a list" |
| 638 | + self.assertErrorRegex(EasyBuildError, error_regex, to_list_of_strings_and_tuples, 'foo') |
| 639 | + self.assertErrorRegex(EasyBuildError, error_regex, to_list_of_strings_and_tuples, 1) |
| 640 | + self.assertErrorRegex(EasyBuildError, error_regex, to_list_of_strings_and_tuples, {'foo': 'bar'}) |
618 | 641 | error_msg = "Expected elements to be of type string, tuple or list" |
619 | 642 | self.assertErrorRegex(EasyBuildError, error_msg, to_list_of_strings_and_tuples, ['foo', 1]) |
620 | 643 | self.assertErrorRegex(EasyBuildError, error_msg, to_list_of_strings_and_tuples, (1,)) |
621 | 644 |
|
| 645 | + def test_to_list_of_strings_and_tuples_and_dicts(self): |
| 646 | + """Test to_list_of_strings_and_tuples_and_dicts function.""" |
| 647 | + |
| 648 | + # no conversion, already right type |
| 649 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts([]), []) |
| 650 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts([()]), [()]) |
| 651 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts(['foo']), ['foo']) |
| 652 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts([{}]), [{}]) |
| 653 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts([('foo', 'bar')]), [('foo', 'bar')]) |
| 654 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts([('foo', 'bar'), 'baz']), [('foo', 'bar'), 'baz']) |
| 655 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts([('x',), 'y', {'z': 1}]), [('x',), 'y', {'z': 1}]) |
| 656 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts(['y', {'z': 1}]), ['y', {'z': 1}]) |
| 657 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts([{'z': 1}, ('x',)]), [{'z': 1}, ('x',)]) |
| 658 | + |
| 659 | + # actual conversion |
| 660 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts(()), []) |
| 661 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts(('foo',)), ['foo']) |
| 662 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts([['bar', 'baz']]), [('bar', 'baz')]) |
| 663 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts((['bar', 'baz'],)), [('bar', 'baz')]) |
| 664 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts(['foo', ['bar', 'baz']]), ['foo', ('bar', 'baz')]) |
| 665 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts(('foo', ['bar', 'baz'])), ['foo', ('bar', 'baz')]) |
| 666 | + self.assertEqual(to_list_of_strings_and_tuples_and_dicts(('x', ['y'], {'z': 1})), ['x', ('y',), {'z': 1}]) |
| 667 | + |
| 668 | + # conversion failures |
| 669 | + error_regex = "Expected value to be a list" |
| 670 | + self.assertErrorRegex(EasyBuildError, error_regex, to_list_of_strings_and_tuples_and_dicts, 'foo') |
| 671 | + self.assertErrorRegex(EasyBuildError, error_regex, to_list_of_strings_and_tuples_and_dicts, 1) |
| 672 | + self.assertErrorRegex(EasyBuildError, error_regex, to_list_of_strings_and_tuples_and_dicts, {'foo': 'bar'}) |
| 673 | + error_msg = "Expected elements to be of type string, tuple, dict or list" |
| 674 | + self.assertErrorRegex(EasyBuildError, error_msg, to_list_of_strings_and_tuples_and_dicts, ['foo', 1]) |
| 675 | + self.assertErrorRegex(EasyBuildError, error_msg, to_list_of_strings_and_tuples_and_dicts, (1,)) |
| 676 | + self.assertErrorRegex(EasyBuildError, error_msg, to_list_of_strings_and_tuples_and_dicts, (1, {'foo': 'bar'})) |
| 677 | + |
622 | 678 | def test_to_sanity_check_paths_dict(self): |
623 | 679 | """Test to_sanity_check_paths_dict function.""" |
624 | 680 | # no conversion, already right type |
|
0 commit comments