Skip to content

Commit d99c228

Browse files
authored
Merge pull request #3726 from boegel/post_pr_test_report_test
enhance test for post_pr_test_report to cover combination of --from-pr and --include-easyblocks-from-pr
2 parents 22b9603 + 4e1e23d commit d99c228

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

easybuild/framework/easyconfig/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def det_easyconfig_paths(orig_paths):
334334
:return: list of paths to easyconfig files
335335
"""
336336
try:
337-
from_prs = [int(pr_nr) for pr_nr in build_option('from_pr')]
337+
from_prs = [int(x) for x in build_option('from_pr')]
338338
except ValueError:
339339
raise EasyBuildError("Argument to --from-pr must be a comma separated list of PR #s.")
340340

easybuild/tools/github.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ def reasons_for_closing(pr_data):
12321232

12331233
robot_paths = build_option('robot_path')
12341234

1235-
pr_files = [path for path in fetch_easyconfigs_from_pr(pr_data['number']) if path.endswith('.eb')]
1235+
pr_files = [p for p in fetch_easyconfigs_from_pr(pr_data['number']) if p.endswith('.eb')]
12361236

12371237
obsoleted = []
12381238
uses_archived_tc = []
@@ -1491,17 +1491,17 @@ def add_pr_labels(pr, branch=GITHUB_DEVELOP_BRANCH):
14911491

14921492
download_repo_path = download_repo(branch=branch, path=tmpdir)
14931493

1494-
pr_files = [path for path in fetch_easyconfigs_from_pr(pr) if path.endswith('.eb')]
1494+
pr_files = [p for p in fetch_easyconfigs_from_pr(pr) if p.endswith('.eb')]
14951495

14961496
file_info = det_file_info(pr_files, download_repo_path)
14971497

14981498
pr_target_account = build_option('pr_target_account')
14991499
github_user = build_option('github_user')
15001500
pr_data, _ = fetch_pr_data(pr, pr_target_account, pr_target_repo, github_user)
1501-
pr_labels = [label['name'] for label in pr_data['labels']]
1501+
pr_labels = [x['name'] for x in pr_data['labels']]
15021502

15031503
expected_labels = det_pr_labels(file_info, pr_target_repo)
1504-
missing_labels = [label for label in expected_labels if label not in pr_labels]
1504+
missing_labels = [x for x in expected_labels if x not in pr_labels]
15051505

15061506
dry_run = build_option('dry_run') or build_option('extended_dry_run')
15071507

easybuild/tools/options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ def set_up_configuration(args=None, logfile=None, testing=False, silent=False):
14641464

14651465
# map list of strings --from-pr value to list of integers
14661466
try:
1467-
from_prs = [int(pr_nr) for pr_nr in eb_go.options.from_pr]
1467+
from_prs = [int(x) for x in eb_go.options.from_pr]
14681468
except ValueError:
14691469
raise EasyBuildError("Argument to --from-pr must be a comma separated list of PR #s.")
14701470

@@ -1500,7 +1500,7 @@ def set_up_configuration(args=None, logfile=None, testing=False, silent=False):
15001500
# done here instead of in _postprocess_include because github integration requires build_options to be initialized
15011501
if eb_go.options.include_easyblocks_from_pr:
15021502
try:
1503-
easyblock_prs = [int(pr_nr) for pr_nr in eb_go.options.include_easyblocks_from_pr]
1503+
easyblock_prs = [int(x) for x in eb_go.options.include_easyblocks_from_pr]
15041504
except ValueError:
15051505
raise EasyBuildError("Argument to --include-easyblocks-from-pr must be a comma separated list of PR #s.")
15061506

easybuild/tools/testing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def create_test_report(msg, ecs_with_res, init_session_state, pr_nrs=None, gist_
151151
test_report = []
152152
if pr_nrs is not None:
153153
repo = pr_target_repo or GITHUB_EASYCONFIGS_REPO
154-
pr_urls = ["https://github.com/%s/%s/pull/%s" % (pr_target_account, repo, pr_nr) for pr_nr in pr_nrs]
154+
pr_urls = ["https://github.com/%s/%s/pull/%s" % (pr_target_account, repo, x) for x in pr_nrs]
155155
test_report.extend([
156156
"Test report for %s" % ', '.join(pr_urls),
157157
"",
@@ -193,7 +193,7 @@ def create_test_report(msg, ecs_with_res, init_session_state, pr_nrs=None, gist_
193193
descr = "(partial) EasyBuild log for failed build of %s" % ec['spec']
194194

195195
if pr_nrs is not None:
196-
descr += " (PR #%s)" % ', #'.join(str(pr_nr) for pr_nr in pr_nrs)
196+
descr += " (PR #%s)" % ', #'.join(str(x) for x in pr_nrs)
197197

198198
if easyblock_pr_nrs:
199199
descr += "".join(" (easyblock PR #%s)" % nr for nr in easyblock_pr_nrs)
@@ -295,7 +295,7 @@ def post_pr_test_report(pr_nr, repo_type, test_report, msg, init_session_state,
295295

296296
if build_option('include_easyblocks_from_pr'):
297297
if repo_type == GITHUB_EASYCONFIGS_REPO:
298-
easyblocks_pr_nrs = [int(eb_pr_nr) for eb_pr_nr in build_option('include_easyblocks_from_pr')]
298+
easyblocks_pr_nrs = [int(x) for x in build_option('include_easyblocks_from_pr')]
299299
comment_lines.append("Using easyblocks from PR(s) %s" %
300300
", ".join(["https://github.com/%s/%s/pull/%s" %
301301
(pr_target_account, GITHUB_EASYBLOCKS_REPO, easyblocks_pr_nr)
@@ -333,12 +333,12 @@ def overall_test_report(ecs_with_res, orig_cnt, success, msg, init_session_state
333333
dump_path = build_option('dump_test_report')
334334

335335
try:
336-
pr_nrs = [int(pr_nr) for pr_nr in build_option('from_pr')]
336+
pr_nrs = [int(x) for x in build_option('from_pr')]
337337
except ValueError:
338338
raise EasyBuildError("Argument to --from-pr must be a comma separated list of PR #s.")
339339

340340
try:
341-
easyblock_pr_nrs = [int(pr_nr) for pr_nr in build_option('include_easyblocks_from_pr')]
341+
easyblock_pr_nrs = [int(x) for x in build_option('include_easyblocks_from_pr')]
342342
except ValueError:
343343
raise EasyBuildError("Argument to --include-easyblocks-from-pr must be a comma separated list of PR #s.")
344344

test/framework/github.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from easybuild.base.rest import RestClient
4242
from easybuild.framework.easyconfig.tools import categorize_files_by_type
4343
from easybuild.tools.build_log import EasyBuildError
44-
from easybuild.tools.config import build_option, module_classes
44+
from easybuild.tools.config import build_option, module_classes, update_build_option
4545
from easybuild.tools.configobj import ConfigObj
4646
from easybuild.tools.filetools import read_file, write_file
4747
from easybuild.tools.github import GITHUB_EASYCONFIGS_REPO, GITHUB_EASYBLOCKS_REPO, GITHUB_MERGEABLE_STATE_CLEAN
@@ -1051,6 +1051,27 @@ def test_pr_test_report(self):
10511051
regex = re.compile(pattern, re.M)
10521052
self.assertTrue(regex.search(stdout), "Pattern '%s' should be found in: %s" % (regex.pattern, stdout))
10531053

1054+
# also test combination of --from-pr and --include-easyblocks-from-pr
1055+
update_build_option('include_easyblocks_from_pr', ['6789'])
1056+
1057+
self.mock_stderr(True)
1058+
self.mock_stdout(True)
1059+
post_pr_test_report('1234', gh.GITHUB_EASYCONFIGS_REPO, test_report, "OK!", init_session_state, True)
1060+
stderr, stdout = self.get_stderr(), self.get_stdout()
1061+
self.mock_stderr(False)
1062+
self.mock_stdout(False)
1063+
1064+
self.assertEqual(stderr, '')
1065+
1066+
patterns = [
1067+
r"^\[DRY RUN\] Adding comment to easybuild-easyconfigs issue #1234: 'Test report by @easybuild_test",
1068+
r"^See https://gist.github.com/DRY_RUN for a full test report.'",
1069+
r"Using easyblocks from PR\(s\) https://github.com/easybuilders/easybuild-easyblocks/pull/6789",
1070+
]
1071+
for pattern in patterns:
1072+
regex = re.compile(pattern, re.M)
1073+
self.assertTrue(regex.search(stdout), "Pattern '%s' should be found in: %s" % (regex.pattern, stdout))
1074+
10541075
def test_create_test_report(self):
10551076
"""Test create_test_report function."""
10561077
logfile = os.path.join(self.test_prefix, 'log.txt')

0 commit comments

Comments
 (0)