From 2b1e3dc04a2538c32e8d28d0936aa53d7b64425b Mon Sep 17 00:00:00 2001 From: Ivan Razumov Date: Mon, 24 Jun 2024 13:23:09 +0200 Subject: [PATCH] Better way to handle fetching PR test results during testing --- process_pr.py | 13 ++++++------- tests/test_process_pr.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/process_pr.py b/process_pr.py index da019fa5bad4..b511a88e0afc 100644 --- a/process_pr.py +++ b/process_pr.py @@ -45,7 +45,6 @@ from _py2with3compatibility import run_cmd from json import dumps, dump, load, loads import yaml -import sys # to test if we are doing tests or are in production mode try: from yaml import CLoader as Loader, CDumper as Dumper @@ -853,13 +852,16 @@ def on_labels_changed(added_labels, removed_labels): pass +def fetch_pr_result(url): + e, o = run_cmd("curl -k -s -L --max-time 60 %s" % url) + return e, o + + def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=False): global L2_DATA if (not force) and ignore_issue(repo_config, repo, issue): return - test_mode = "pytest" in sys.modules - gh_user_char = "@" if not notify_user(issue): gh_user_char = "" @@ -1956,10 +1958,7 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F + "/pr-result" ) print("PR Result:", url) - if test_mode: - e, o = "", "ook" - else: - e, o = run_cmd("curl -k -s -L --max-time 60 %s" % url) + e, o = fetch_pr_result(result_url) if e: print(o) raise Exception("System-error: unable to get PR result") diff --git a/tests/test_process_pr.py b/tests/test_process_pr.py index 71669acfac66..0ece7ad21ecd 100644 --- a/tests/test_process_pr.py +++ b/tests/test_process_pr.py @@ -231,6 +231,13 @@ def on_labels_changed(*args, **kwargs): actions.append({"type": "remove-label", "data": sorted(list(removed_labels))}) +def dummy_fetch_pr_result(*args, **kwargs): + assert len(args) == 1, "Signature of process_pr.fetch_pr_result changed" + assert len(kwargs) == 0, "Signature of process_pr.fetch_pr_result changed" + + return "", "ook" + + class TestProcessPr(Framework.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -340,6 +347,13 @@ def setUpHooks(self): "hook_function": on_labels_changed, "call_original": False, }, + { + "module_path": "process_pr", + "class_name": None, + "function_name": "fetch_pr_result", + "hook_function": dummy_fetch_pr_result, + "call_original": False, + }, # TODO: remove once we update PyGithub { "module_path": "github.IssueComment",