|
33 | 33 | import random |
34 | 34 | import re |
35 | 35 | import sys |
| 36 | +import textwrap |
36 | 37 | from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered, init_config |
37 | 38 | from time import gmtime |
38 | 39 | from unittest import TextTestRunner |
39 | 40 |
|
40 | 41 | import easybuild.tools.testing |
41 | 42 | from easybuild.base.rest import RestClient |
| 43 | +from easybuild.framework.easyconfig.easyconfig import EasyConfig |
42 | 44 | from easybuild.framework.easyconfig.tools import categorize_files_by_type |
43 | 45 | from easybuild.tools.build_log import EasyBuildError |
44 | 46 | from easybuild.tools.config import build_option, module_classes, update_build_option |
@@ -803,53 +805,103 @@ def test_github_det_patch_specs(self): |
803 | 805 | """Test for det_patch_specs function.""" |
804 | 806 |
|
805 | 807 | patch_paths = [os.path.join(self.test_prefix, p) for p in ['1.patch', '2.patch', '3.patch']] |
806 | | - file_info = {'ecs': [ |
807 | | - {'name': 'A', 'patches': ['1.patch'], 'exts_list': []}, |
808 | | - {'name': 'B', 'patches': [], 'exts_list': []}, |
809 | | - ] |
810 | | - } |
| 808 | + file_info = {'ecs': []} |
| 809 | + |
| 810 | + rawtxt = textwrap.dedent(""" |
| 811 | + easyblock = 'ConfigureMake' |
| 812 | + name = 'A' |
| 813 | + version = '42' |
| 814 | + homepage = 'http://foo.com/' |
| 815 | + description = '' |
| 816 | + toolchain = {"name":"GCC", "version": "4.6.3"} |
| 817 | +
|
| 818 | + patches = ['1.patch'] |
| 819 | + """) |
| 820 | + file_info['ecs'].append(EasyConfig(None, rawtxt=rawtxt)) |
| 821 | + rawtxt = textwrap.dedent(""" |
| 822 | + easyblock = 'ConfigureMake' |
| 823 | + name = 'B' |
| 824 | + version = '42' |
| 825 | + homepage = 'http://foo.com/' |
| 826 | + description = '' |
| 827 | + toolchain = {"name":"GCC", "version": "4.6.3"} |
| 828 | + """) |
| 829 | + file_info['ecs'].append(EasyConfig(None, rawtxt=rawtxt)) |
| 830 | + |
811 | 831 | error_pattern = "Failed to determine software name to which patch file .*/2.patch relates" |
812 | 832 | self.mock_stdout(True) |
813 | 833 | self.assertErrorRegex(EasyBuildError, error_pattern, gh.det_patch_specs, patch_paths, file_info, []) |
814 | 834 | self.mock_stdout(False) |
815 | 835 |
|
816 | | - file_info['ecs'].append({'name': 'C', 'patches': [('3.patch', 'subdir'), '2.patch'], 'exts_list': []}) |
| 836 | + rawtxt = textwrap.dedent(""" |
| 837 | + easyblock = 'ConfigureMake' |
| 838 | + name = 'C' |
| 839 | + version = '42' |
| 840 | + homepage = 'http://foo.com/' |
| 841 | + description = '' |
| 842 | + toolchain = {"name":"GCC", "version": "4.6.3"} |
| 843 | +
|
| 844 | + patches = [('3.patch', 'subdir'), '2.patch'] |
| 845 | + """) |
| 846 | + file_info['ecs'].append(EasyConfig(None, rawtxt=rawtxt)) |
817 | 847 | self.mock_stdout(True) |
818 | 848 | res = gh.det_patch_specs(patch_paths, file_info, []) |
819 | 849 | self.mock_stdout(False) |
820 | 850 |
|
821 | | - self.assertEqual(len(res), 3) |
822 | | - self.assertEqual(os.path.basename(res[0][0]), '1.patch') |
823 | | - self.assertEqual(res[0][1], 'A') |
824 | | - self.assertEqual(os.path.basename(res[1][0]), '2.patch') |
825 | | - self.assertEqual(res[1][1], 'C') |
826 | | - self.assertEqual(os.path.basename(res[2][0]), '3.patch') |
827 | | - self.assertEqual(res[2][1], 'C') |
| 851 | + self.assertEqual([i[0] for i in res], patch_paths) |
| 852 | + self.assertEqual([i[1] for i in res], ['A', 'C', 'C']) |
828 | 853 |
|
829 | 854 | # check if patches for extensions are found |
830 | | - file_info['ecs'][-1] = { |
831 | | - 'name': 'patched_ext', |
832 | | - 'patches': [], |
833 | | - 'exts_list': [ |
| 855 | + rawtxt = textwrap.dedent(""" |
| 856 | + easyblock = 'ConfigureMake' |
| 857 | + name = 'patched_ext' |
| 858 | + version = '42' |
| 859 | + homepage = 'http://foo.com/' |
| 860 | + description = '' |
| 861 | + toolchain = {"name":"GCC", "version": "4.6.3"} |
| 862 | +
|
| 863 | + exts_list = [ |
834 | 864 | 'foo', |
835 | 865 | ('bar', '1.2.3'), |
836 | 866 | ('patched', '4.5.6', { |
837 | | - 'patches': [('2.patch', 1), '3.patch'], |
| 867 | + 'patches': [('%(name)s-2.patch', 1), '%(name)s-3.patch'], |
838 | 868 | }), |
839 | | - ], |
840 | | - } |
| 869 | + ] |
| 870 | + """) |
| 871 | + patch_paths[1:3] = [os.path.join(self.test_prefix, p) for p in ['patched-2.patch', 'patched-3.patch']] |
| 872 | + file_info['ecs'][-1] = EasyConfig(None, rawtxt=rawtxt) |
| 873 | + |
| 874 | + self.mock_stdout(True) |
| 875 | + res = gh.det_patch_specs(patch_paths, file_info, []) |
| 876 | + self.mock_stdout(False) |
| 877 | + |
| 878 | + self.assertEqual([i[0] for i in res], patch_paths) |
| 879 | + self.assertEqual([i[1] for i in res], ['A', 'patched_ext', 'patched_ext']) |
| 880 | + |
| 881 | + # check if patches for components are found |
| 882 | + rawtxt = textwrap.dedent(""" |
| 883 | + easyblock = 'PythonBundle' |
| 884 | + name = 'patched_bundle' |
| 885 | + version = '42' |
| 886 | + homepage = 'http://foo.com/' |
| 887 | + description = '' |
| 888 | + toolchain = {"name":"GCC", "version": "4.6.3"} |
| 889 | +
|
| 890 | + components = [ |
| 891 | + ('bar', '1.2.3'), |
| 892 | + ('patched', '4.5.6', { |
| 893 | + 'patches': [('%(name)s-2.patch', 1), '%(name)s-3.patch'], |
| 894 | + }), |
| 895 | + ] |
| 896 | + """) |
| 897 | + file_info['ecs'][-1] = EasyConfig(None, rawtxt=rawtxt) |
841 | 898 |
|
842 | 899 | self.mock_stdout(True) |
843 | 900 | res = gh.det_patch_specs(patch_paths, file_info, []) |
844 | 901 | self.mock_stdout(False) |
845 | 902 |
|
846 | | - self.assertEqual(len(res), 3) |
847 | | - self.assertEqual(os.path.basename(res[0][0]), '1.patch') |
848 | | - self.assertEqual(res[0][1], 'A') |
849 | | - self.assertEqual(os.path.basename(res[1][0]), '2.patch') |
850 | | - self.assertEqual(res[1][1], 'patched_ext') |
851 | | - self.assertEqual(os.path.basename(res[2][0]), '3.patch') |
852 | | - self.assertEqual(res[2][1], 'patched_ext') |
| 903 | + self.assertEqual([i[0] for i in res], patch_paths) |
| 904 | + self.assertEqual([i[1] for i in res], ['A', 'patched_bundle', 'patched_bundle']) |
853 | 905 |
|
854 | 906 | def test_github_restclient(self): |
855 | 907 | """Test use of RestClient.""" |
|
0 commit comments