Skip to content

Commit b4db0fe

Browse files
committed
Add test for postinstallpatches handling in GitHub integration
1 parent 9875d39 commit b4db0fe

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

easybuild/base/testing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ def get_stderr(self):
201201
"""Return output captured from stderr until now."""
202202
return sys.stderr.getvalue()
203203

204+
@contextmanager
205+
def mocked_stdout(self):
206+
"""Context manager to mock stdout"""
207+
self.mock_stdout(True)
208+
try:
209+
yield sys.stdout
210+
finally:
211+
self.mock_stdout(False)
212+
204213
@contextmanager
205214
def mocked_stdout_stderr(self, mock_stdout=True, mock_stderr=True):
206215
"""Context manager to mock stdout and stderr"""

test/framework/github.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ def tearDown(self):
120120

121121
def test_det_pr_title(self):
122122
"""Test det_pr_title function"""
123-
# check if patches for extensions are found
124123
rawtxt = textwrap.dedent("""
125124
easyblock = 'ConfigureMake'
126125
name = '%s'
@@ -995,9 +994,8 @@ def test_github_det_patch_specs(self):
995994
file_info['ecs'].append(EasyConfig(None, rawtxt=rawtxt))
996995

997996
error_pattern = "Failed to determine software name to which patch file .*/2.patch relates"
998-
self.mock_stdout(True)
999-
self.assertErrorRegex(EasyBuildError, error_pattern, gh.det_patch_specs, patch_paths, file_info, [])
1000-
self.mock_stdout(False)
997+
with self.mocked_stdout():
998+
self.assertErrorRegex(EasyBuildError, error_pattern, gh.det_patch_specs, patch_paths, file_info, [])
1001999

10021000
rawtxt = textwrap.dedent("""
10031001
easyblock = 'ConfigureMake'
@@ -1007,12 +1005,11 @@ def test_github_det_patch_specs(self):
10071005
description = ''
10081006
toolchain = {"name":"GCC", "version": "4.6.3"}
10091007
1010-
patches = [('3.patch', 'subdir'), '2.patch']
1008+
postinstallpatches = [('3.patch', 'subdir'), '2.patch']
10111009
""")
10121010
file_info['ecs'].append(EasyConfig(None, rawtxt=rawtxt))
1013-
self.mock_stdout(True)
1014-
res = gh.det_patch_specs(patch_paths, file_info, [])
1015-
self.mock_stdout(False)
1011+
with self.mocked_stdout():
1012+
res = gh.det_patch_specs(patch_paths, file_info, [])
10161013

10171014
self.assertEqual([i[0] for i in res], patch_paths)
10181015
self.assertEqual([i[1] for i in res], ['A', 'C', 'C'])
@@ -1031,20 +1028,24 @@ def test_github_det_patch_specs(self):
10311028
('bar', '1.2.3'),
10321029
('patched', '4.5.6', {
10331030
'patches': [('%(name)s-2.patch', 1), '%(name)s-3.patch'],
1031+
'postinstallpatches': ['%(name)s-4.patch'],
10341032
}),
10351033
]
1034+
postinstallpatches = ['%(name)s-5.patch'],
10361035
""")
1037-
patch_paths[1:3] = [os.path.join(self.test_prefix, p) for p in ['patched-2.patch', 'patched-3.patch']]
1036+
patch_paths[1:] = [os.path.join(self.test_prefix, p) for p in
1037+
['patched-2.patch', 'patched-3.patch', 'patched-4.patch', 'patched_ext-5.patch']]
10381038
file_info['ecs'][-1] = EasyConfig(None, rawtxt=rawtxt)
10391039

1040-
self.mock_stdout(True)
1041-
res = gh.det_patch_specs(patch_paths, file_info, [])
1042-
self.mock_stdout(False)
1040+
with self.mocked_stdout():
1041+
res = gh.det_patch_specs(patch_paths, file_info, [])
10431042

10441043
self.assertEqual([i[0] for i in res], patch_paths)
1045-
self.assertEqual([i[1] for i in res], ['A', 'patched_ext', 'patched_ext'])
1044+
self.assertEqual([i[1] for i in res], ['A'] + ['patched_ext'] * 4)
10461045

10471046
# check if patches for components are found
1047+
# NOTE: Using alternative name and tuple format for post_install_patches, different to above test case
1048+
# to verify handling either way works without adding another sub-test
10481049
rawtxt = textwrap.dedent("""
10491050
easyblock = 'PythonBundle'
10501051
name = 'patched_bundle'
@@ -1057,17 +1058,19 @@ def test_github_det_patch_specs(self):
10571058
('bar', '1.2.3'),
10581059
('patched', '4.5.6', {
10591060
'patches': [('%(name)s-2.patch', 1), '%(name)s-3.patch'],
1061+
'post_install_patches': [('%(name)s-4.patch', 1)],
10601062
}),
10611063
]
1064+
post_install_patches = [('%(name)s-5.patch', 2)]
10621065
""")
1066+
patch_paths[-1] = 'patched_bundle-5.patch'
10631067
file_info['ecs'][-1] = EasyConfig(None, rawtxt=rawtxt)
10641068

1065-
self.mock_stdout(True)
1066-
res = gh.det_patch_specs(patch_paths, file_info, [])
1067-
self.mock_stdout(False)
1069+
with self.mocked_stdout():
1070+
res = gh.det_patch_specs(patch_paths, file_info, [])
10681071

10691072
self.assertEqual([i[0] for i in res], patch_paths)
1070-
self.assertEqual([i[1] for i in res], ['A', 'patched_bundle', 'patched_bundle'])
1073+
self.assertEqual([i[1] for i in res], ['A'] + ['patched_bundle'] * 4)
10711074

10721075
def test_github_restclient(self):
10731076
"""Test use of RestClient."""

0 commit comments

Comments
 (0)