nchammas commented on code in PR #60779:
URL: https://github.com/apache/spark/pull/60779#discussion_r4659701975


##########
dev/merge_spark_pr.py:
##########
@@ -4230,1051 +4230,52 @@ def record(pair):
         update_jira_for_pr(pr_num, title, merged_refs)
 
 
-__test__ = {
-    "abort_entrypoint": """
-    After [a]bort at the checkout-retry prompt no git runs again, by any route 
out: the CLI
-    handler, or a fail() in main()'s finally blocks such as declining the JIRA 
prompt. An
-    ordinary exit still cleans up.
-
-    >>> import ast, doctest
-    >>> from pathlib import Path
-    >>> from contextlib import redirect_stdout
-    >>> from io import StringIO
-    >>> from unittest.mock import patch
-    >>> entrypoint = ast.parse(Path(__file__).read_bytes()).body[-1]
-    >>> code = compile(ast.Module(body=[entrypoint], type_ignores=[]), 
__file__, "exec")
-    >>> refused = subprocess.CalledProcessError(1, "git checkout")
-    >>> def abort_then_fail():
-    ...     try:
-    ...         _restore_original_head()
-    ...     finally:
-    ...         fail("Okay, exiting")
-    >>> def ordinary_exit():
-    ...     raise SystemExit(-1)
-    >>> for entry in (_restore_original_head, abort_then_fail, ordinary_exit):
-    ...     with (
-    ...         patch.object(doctest, "testmod", return_value=(0, 0)),
-    ...         patch.dict(clean_up.__globals__, original_head="master",
-    ...                    preserve_local_state=False),
-    ...         patch.object(git, "run", side_effect=refused) as run,
-    ...         patch("builtins.input", side_effect=["a"]), 
redirect_stdout(StringIO()),
-    ...     ):
-    ...         try:
-    ...             exec(code, dict(globals(), __name__="__main__", 
main=entry))
-    ...         except BaseException as e:
-    ...             ended = getattr(e, "code", type(e).__name__)
-    ...     cmds = [c.args[0] if isinstance(c.args[0], str) else " 
".join(c.args[0])
-    ...             for c in run.call_args_list]
-    ...     print(entry.__name__, [cmd.split()[1] for cmd in cmds], ended)
-    _restore_original_head ['checkout'] -1
-    abort_then_fail ['checkout'] -1
-    ordinary_exit ['checkout'] CalledProcessError
-
-    The flag clean_up() reads is off again, and one left on stops the run 
before main():
-
-    >>> clean_up.__globals__["preserve_local_state"]
-    False
-    >>> ran = []
-    >>> with patch.object(doctest, "testmod", return_value=(0, 0)):
-    ...     try:
-    ...         exec(code, dict(globals(), __name__="__main__", main=lambda: 
ran.append(1),
-    ...                         preserve_local_state=True))
-    ...     except SystemExit as e:
-    ...         print(e.code, ran)
-    -1 []
-    """,
-    "revert_jira_issue": """
-    A revert removes the versions for its branches while preserving released, 
archived,
-    and unrelated versions. JIRA receives individual removals so concurrent 
additions survive.
-
-    >>> from contextlib import redirect_stdout
-    >>> from io import StringIO
-    >>> from types import SimpleNamespace
-    >>> from unittest.mock import Mock, call, patch
-    >>> def version(name, released=False, archived=False):
-    ...     return SimpleNamespace(
-    ...         name=name, raw={"name": name, "released": released, 
"archived": archived})
-    >>> versions = [version("5.0.0"), version("4.3.0"), version("4.2.1", 
released=True),
-    ...             version("4.2.0", archived=True), version("3.5.2")]
-    >>> issue = Mock(key="SPARK-1234")
-    >>> issue.fields.fixVersions = versions
-    >>> issue.fields.status.name = "Open"
-    >>> client = Mock()
-    >>> client.project_versions.return_value = versions
-    >>> writer = Jira(client)
-    >>> def run_revert(answers):
-    ...     issue.reset_mock()
-    ...     client.reset_mock()
-    ...     output = StringIO()
-    ...     with (
-    ...         patch.dict(revert_jira_issue.__globals__, asf_jira=client,
-    ...                    jira_ops=writer, 
get_jira_issue=Mock(return_value=issue)),
-    ...         patch("builtins.input", side_effect=answers),
-    ...         redirect_stdout(output),
-    ...     ):
-    ...         revert_jira_issue(["master", "branch-4.x"], "SPARK-1234")
-    ...     return output.getvalue()
-    >>> output = run_revert(["", "y"])
-    >>> issue.update.assert_called_once_with(update={"fixVersions": [
-    ...     {"remove": {"name": "5.0.0"}}, {"remove": {"name": "4.3.0"}}]})
-    >>> client.mock_calls
-    [call.project_versions('SPARK')]
-
-    The committer can narrow the selection, decline confirmation, or skip the 
update.
-
-    >>> output = run_revert(["5.0.0", "y"])
-    >>> issue.update.assert_called_once_with(
-    ...     update={"fixVersions": [{"remove": {"name": "5.0.0"}}]})
-    >>> for answers in (["", "n"], ["", ""], ["skip"]):
-    ...     output = run_revert(answers)
-    ...     issue.update.assert_not_called()
-
-    Released, archived, and unrecorded versions are rejected even when entered 
manually.
-
-    >>> output = run_revert(["4.2.1", "4.2.0", "9.9.9", "", "y"])
-    >>> output.count("Select only unreleased fix versions currently recorded 
on this JIRA.")
-    3
-    >>> issue.update.assert_called_once_with(update={"fixVersions": [
-    ...     {"remove": {"name": "5.0.0"}}, {"remove": {"name": "4.3.0"}}]})
-
-    Dry runs log the removal without writing to JIRA.
-
-    >>> writer = DryRunJira(client)
-    >>> output = run_revert(["", "y"])
-    >>> "DRY-RUN: would remove fixVersions=['5.0.0', '4.3.0'] from JIRA 
SPARK-1234." in output
-    True
-    >>> issue.update.assert_not_called()
-    >>> client.mock_calls
-    [call.project_versions('SPARK')]
-
-    Removing the last fix versions is allowed. A rerun with no matching 
versions is a no-op.
-
-    >>> writer = Jira(client)
-    >>> issue.fields.fixVersions = versions[:2]
-    >>> output = run_revert(["", "y"])
-    >>> issue.update.assert_called_once_with(update={"fixVersions": [
-    ...     {"remove": {"name": "5.0.0"}}, {"remove": {"name": "4.3.0"}}]})
-    >>> issue.fields.fixVersions = versions[2:]
-    >>> output = run_revert([""])
-    >>> issue.update.assert_not_called()
-    >>> issue.fields.fixVersions = []
-    >>> output = run_revert([])
-    >>> "no unreleased fix versions to remove" in output
-    True
-    >>> issue.update.assert_not_called()
-
-    Resolved and closed tickets can be reopened even when no fix versions 
remain.
-
-    >>> client.transitions.return_value = [
-    ...     {"id": "701", "name": "Close Issue"}, {"id": "3", "name": "Reopen 
Issue"}]
-    >>> for status in ("Resolved", "Closed"):
-    ...     issue.fields.status.name = status
-    ...     output = run_revert(["y"])
-    ...     client.transitions.assert_called_once_with("SPARK-1234")
-    ...     client.transition_issue.assert_called_once_with("SPARK-1234", "3")
-    ...     issue.update.assert_not_called()
-
-    Reopening is optional and independent of fix-version removal.
-
-    >>> for answer in ("n", ""):
-    ...     output = run_revert([answer])
-    ...     client.transitions.assert_not_called()
-    ...     client.transition_issue.assert_not_called()
-    >>> issue.fields.fixVersions = versions
-    >>> output = run_revert(["", "y", "y"])
-    >>> issue.update.assert_called_once_with(update={"fixVersions": [
-    ...     {"remove": {"name": "5.0.0"}}, {"remove": {"name": "4.3.0"}}]})
-    >>> client.transition_issue.assert_called_once_with("SPARK-1234", "3")
-    >>> for answers in (["skip", "y"], ["", "n", "y"]):
-    ...     output = run_revert(answers)
-    ...     issue.update.assert_not_called()
-    ...     client.transition_issue.assert_called_once_with("SPARK-1234", "3")
-    >>> output = run_revert(["", "y", "n"])
-    >>> issue.update.assert_called_once()
-    >>> client.transition_issue.assert_not_called()
-
-    Dry runs log both updates and leave JIRA untouched.
-
-    >>> writer = DryRunJira(client)
-    >>> output = run_revert(["", "y", "y"])
-    >>> "DRY-RUN: would remove fixVersions=" in output
-    True
-    >>> "DRY-RUN: would reopen JIRA SPARK-1234." in output
-    True
-    >>> issue.update.assert_not_called()
-    >>> client.transition_issue.assert_not_called()
-
-    Unavailable transitions report that manual action is needed.
-
-    >>> writer = Jira(client)
-    >>> client.transitions.return_value = [{"id": "701", "name": "Close 
Issue"}]
-    >>> output = run_revert(["skip", "y"])
-    >>> "No Reopen Issue transition available for SPARK-1234; reopen it 
manually." in output
-    True
-    >>> client.transition_issue.assert_not_called()
-
-    Lookup and transition failures are nonfatal and request manual reopening.
-
-    >>> client.transitions.side_effect = RuntimeError("lookup failed")
-    >>> output = run_revert(["skip", "y"])
-    >>> "Failed to reopen SPARK-1234; reopen it manually: lookup failed" in 
output
-    True
-    >>> client.transition_issue.assert_not_called()
-    >>> client.transitions.side_effect = None
-    >>> client.transitions.return_value = [{"id": "3", "name": "Reopen Issue"}]
-    >>> client.transition_issue.side_effect = RuntimeError("permission denied")
-    >>> output = run_revert(["skip", "y"])
-    >>> "Failed to reopen SPARK-1234; reopen it manually: permission denied" 
in output
-    True
-    >>> client.transition_issue.assert_called_once_with("SPARK-1234", "3")
-    >>> client.transition_issue.side_effect = None
-
-    Active tickets require no reopening prompt or transition lookup.
-
-    >>> issue.fields.fixVersions = []
-    >>> for status in ("Open", "In Progress", "Reopened"):
-    ...     issue.fields.status.name = status
-    ...     output = run_revert([])
-    ...     client.transitions.assert_not_called()
-    ...     client.transition_issue.assert_not_called()
-    """,
-    "update_jira_for_revert": """
-    Reverts update each leading JIRA id once and bypass the resolve/add path. 
The
-    direction comes from the title's wrappers (see _is_net_revert), so a net 
re-land
-    resolves.
-
-    >>> from contextlib import redirect_stdout
-    >>> from io import StringIO
-    >>> from unittest.mock import Mock, call, patch
-    >>> reverter, resolver, confirm = Mock(), Mock(), Mock()
-    >>> def update(title, branches):
-    ...     reverter.reset_mock()
-    ...     resolver.reset_mock()
-    ...     confirm.reset_mock()
-    ...     with (
-    ...         patch.dict(update_jira_for_pr.__globals__, 
revert_jira_issue=reverter,
-    ...                    resolve_jira_issue=resolver, 
continue_maybe=confirm),
-    ...         redirect_stdout(StringIO()),
-    ...     ):
-    ...         update_jira_for_pr("123", title, branches)
-    >>> title = 'Revert "[SPARK-1234][SPARK-5678][SQL] Fix mentions 
SPARK-9999"'
-    >>> update(title, ["master", "branch-4.x"])
-    >>> assert reverter.call_args_list == [
-    ...     call(['master', 'branch-4.x'], 'SPARK-1234'),
-    ...     call(['master', 'branch-4.x'], 'SPARK-5678')]
-    >>> resolver.assert_not_called()
-
-    Backport-only runs use the same revert path. A missing JIRA id is entered 
interactively.
-
-    >>> update('Revert "[SPARK-1234][SQL] Fix"', ["branch-4.2"])
-    >>> reverter.assert_called_once_with(["branch-4.2"], "SPARK-1234")
-    >>> update('Revert "Fix"', ["master"])
-    >>> reverter.assert_called_once_with(["master"], "")
-
-    A bare leading id, as in the old subject SPARK-49004, still reaches the 
revert path.
-
-    >>> update('Revert "SPARK-49004"', ["master"])
-    >>> reverter.assert_called_once_with(["master"], "SPARK-49004")
-
-    Wrapped skip tags follow the same policy as direct merges for FOLLOWUP, 
including the
-    FOLLOW-UP alias, and for MINOR and TRIVIAL when the title has no leading 
id. The tags are
-    read even from a wrapped title that Title.parse rejects.
-
-    >>> for title in ('Revert "[MINOR][SQL] Fix"', 'Revert "[TRIVIAL][SQL] 
Fix"',
-    ...               'Revert "[SPARK-1234][SQL][FOLLOWUP] Fix"',
-    ...               'Revert "[SPARK-1234][SQL][FOLLOW-UP] Fix"',
-    ...               'Revert "[SPARK-1234][SQL][FOLLOWUP][MINOR] Fix"',
-    ...               'Revert "[MINOR][TRIVIAL][SQL] Fix"', 'Revert 
"[SQL][MINOR] Fix"',
-    ...               'Revert "[MINOR][SPARK-1234] Fix"'):
-    ...     update(title, ["master"])
-    ...     reverter.assert_not_called()
-    ...     resolver.assert_not_called()
-    ...     confirm.assert_not_called()
-
-    Title.parse rejects an id next to MINOR or TRIVIAL, and so does the 
component prompt, so
-    only an older subject opens with an id and has one. Such a commit was 
normally merged as
-    the fix for its id, so the id is updated.
-
-    >>> update('Revert "[SPARK-1234][SQL][MINOR] Fix"', ["master"])
-    >>> reverter.assert_called_once_with(["master"], "SPARK-1234")
-
-    The skip tags come from the title alone, so direct merges skip through it.
-
-    >>> for title in ("[MINOR][SQL] Fix", "[TRIVIAL][SQL] Fix", 
"[SPARK-1234][SQL][FOLLOWUP] Fix"):
-    ...     update(title, ["master"])
-    ...     reverter.assert_not_called()
-    ...     resolver.assert_not_called()
-    ...     confirm.assert_not_called()
-
-    Reapply titles are unwrapped too, so their skip tags apply as well.
-
-    >>> for title in ('Reapply "[MINOR][SQL] Fix"', 'Reapply 
"[SPARK-1234][SQL][FOLLOWUP] Fix"',
-    ...               'Reapply "[SPARK-1234][SQL][FOLLOW-UP] Fix"',
-    ...               'Reapply "[SPARK-1234][SQL][FOLLOWUP][MINOR] Fix"'):
-    ...     update(title, ["master"])
-    ...     reverter.assert_not_called()
-    ...     resolver.assert_not_called()
-    ...     confirm.assert_not_called()
-
-    Nested wrappers are unwrapped before the skip-tag and id checks, so an 
inner
-    skip tag is still honored and an inner id still reaches the revert path. A
-    revert of a reapply nets to a revert.
-
-    >>> update('Revert "Reapply "[MINOR][SQL] Fix""', ["master"])
-    >>> reverter.assert_not_called()
-    >>> resolver.assert_not_called()
-    >>> confirm.assert_not_called()
-    >>> update('Revert "Reapply "[SPARK-1234][SQL] Fix""', ["master"])
-    >>> reverter.assert_called_once_with(["master"], "SPARK-1234")
-
-    Ordinary merges and reapplies resolve the leading id, not an id in the 
title body. The
-    components to reconcile are read from an ordinary title; a Revert/Reapply 
title, or an
-    older subject that Title.parse rejects, has none.
-
-    >>> for title, components in (('[SPARK-1234][SQL] Fix mentions 
SPARK-9999', ['SQL']),
-    ...                           ('[SPARK-1234][sql][DOCS] Fix', ['SQL', 
'DOC']),
-    ...                           ('Reapply "[SPARK-1234][SQL] Fix"', []),
-    ...                           ('Reapply "[SPARK-1234][SQL][TRIVIAL] Fix"', 
[]),
-    ...                           ('[SPARK-1234][SQL][MINOR] Fix', [])):
-    ...     update(title, ["master"])
-    ...     reverter.assert_not_called()
-    ...     resolver.assert_called_once_with(
-    ...         ["master"],
-    ...         "Issue resolved by pull request 
123\\n[https://github.com/apache/spark/pull/123]";,
-    ...         "SPARK-1234", title_components=components)
-    >>> update("[SPARK-1234][SPARK-5678][SQL] Fix", ["master"])
-    >>> [c.args[2] for c in resolver.call_args_list]
-    ['SPARK-1234', 'SPARK-5678']
-
-    The direction is decided by all the wrappers, not only the outermost one: 
a revert
-    of a revert re-lands the change and resolves the id, while a reapply of a 
revert
-    reverts it.
-
-    >>> update('Revert "Revert "[SPARK-1234][SQL] Fix""', ["master"])
-    >>> reverter.assert_not_called()
-    >>> resolver.assert_called_once_with(
-    ...     ["master"],
-    ...     "Issue resolved by pull request 
123\\n[https://github.com/apache/spark/pull/123]";,
-    ...     "SPARK-1234", title_components=[])
-    >>> update('Reapply "Revert "[SPARK-1234][SQL] Fix""', ["master"])
-    >>> reverter.assert_called_once_with(["master"], "SPARK-1234")
-    >>> resolver.assert_not_called()
-
-    A title without an id still offers to resolve one that the committer 
enters.
-
-    >>> update('Reapply "Fix"', ["master"])
-    >>> resolver.assert_called_once_with(
-    ...     ["master"],
-    ...     "Issue resolved by pull request 
123\\n[https://github.com/apache/spark/pull/123]";,
-    ...     title_components=[])
-
-    When JIRA was disabled at startup (unreachable), every shape of update is 
skipped: no
-    prompt, no resolve, no revert. The disabled message is the one printed 
even for titles
-    carrying skip tags, so the committer is told JIRA was the reason.
-
-    >>> def update_disabled(title):
-    ...     reverter.reset_mock()
-    ...     resolver.reset_mock()
-    ...     confirm.reset_mock()
-    ...     output = StringIO()
-    ...     with (
-    ...         patch.dict(update_jira_for_pr.__globals__, 
revert_jira_issue=reverter,
-    ...                    resolve_jira_issue=resolver, continue_maybe=confirm,
-    ...                    jira_disabled=True),
-    ...         redirect_stdout(output),
-    ...     ):
-    ...         update_jira_for_pr("123", title, ["master"])
-    ...     assert not reverter.called
-    ...     assert not resolver.called
-    ...     assert not confirm.called
-    ...     return output.getvalue()
-    >>> disabled_outputs = [
-    ...     update_disabled(t)
-    ...     for t in ('[SPARK-1234][SQL] Fix', 'Revert "[SPARK-1234][SQL] 
Fix"',
-    ...               'Revert "[MINOR][SQL] Fix"', 
'[SPARK-1234][SQL][FOLLOWUP] Fix')]
-    >>> all("JIRA is disabled; skipping JIRA update for PR #123" in o for o in 
disabled_outputs)
-    True
-    >>> all("because title has" not in o for o in disabled_outputs)
-    True
-    """,
-    "prompt_for_components": """
-    The prompt rejects MINOR and TRIVIAL, which belong at the start of the 
title, tokens that
-    the bracket-tag scan cannot read back, and SPARK ids, and asks again until 
the components
-    include a primary one.
-
-    >>> from contextlib import redirect_stdout
-    >>> from io import StringIO
-    >>> from unittest.mock import patch
-    >>> output = StringIO()
-    >>> answers = ["sql,minor", " Trivial ", "sql, spark core", "sql,[tests]", 
"sql,spark-2",
-    ...            "sql][minor", "tests", "sql, follow-up"]
-    >>> with (
-    ...     patch.dict(prompt_for_components.__globals__, bold_input=lambda _: 
answers.pop(0)),
-    ...     redirect_stdout(output),
-    ... ):
-    ...     components = prompt_for_components()
-    >>> components
-    ['SQL', 'FOLLOWUP']
-    >>> answers
-    []
-    >>> "[MINOR] cannot be entered here" in output.getvalue()
-    True
-    >>> "[TRIVIAL] cannot be entered here" in output.getvalue()
-    True
-    >>> for bad in ("SPARK CORE", "[TESTS]", "SPARK-2", "SQL][MINOR"):
-    ...     assert "Invalid component(s): %s." % bad in output.getvalue(), bad
-    """,
-    "prepare_merge_title": """
-    An ordinary title is parsed and its components are normalized in it, 
prompting for a
-    primary component when there is none. A changed title is printed.
-
-    >>> from unittest.mock import Mock, patch
-    >>> stop, prompt = Mock(side_effect=SystemExit), 
Mock(return_value=["CORE"])
-    >>> def prepare(title):
-    ...     stop.reset_mock()
-    ...     prompt.reset_mock()
-    ...     with patch.dict(prepare_merge_title.__globals__, fail=stop,
-    ...                     prompt_for_components=prompt):
-    ...         try:
-    ...             return prepare_merge_title(title)
-    ...         except SystemExit:
-    ...             return stop.call_args.args[0]
-    >>> prepare("[SPARK-1234][SQL] Fix")
-    '[SPARK-1234][SQL] Fix'
-    >>> prepare("[SPARK-1234][FOLLOWUP][sql] Fix")
-    Normalized title: [SPARK-1234][SQL][FOLLOWUP] Fix
-    '[SPARK-1234][SQL][FOLLOWUP] Fix'
-    >>> prepare("[SPARK-1234] Fix")
-    Normalized title: [SPARK-1234][CORE] Fix
-    '[SPARK-1234][CORE] Fix'
-    >>> prepare("[SPARK-1234][SQL][4.2][sql] Fix")
-    Normalized title: [SPARK-1234][4.2][SQL] Fix
-    '[SPARK-1234][4.2][SQL] Fix'
-    >>> with patch.dict(prepare_merge_title.__globals__, print_error=print):
-    ...     prepare("[SPARK-1234][SQL][BOGUS] Fix")
-    Title has unknown tag(s): [BOGUS]
-    '[SPARK-1234][SQL][BOGUS] Fix'
-    >>> prepare("[SQL] Fix")
-    "Malformed PR title: title must start with [SPARK-NNNNN], [MINOR], or 
[TRIVIAL]: '[SQL] Fix'"
-
-    A Revert/Reapply title, nested or not, is kept as is, without a prompt.
-
-    >>> for title in ('Revert "[SPARK-1234][SQL] Fix"', 'Revert "Revert 
"[SPARK-1234][SQL] Fix""',
-    ...               'Reapply "[SPARK-1234][SQL] Fix"',
-    ...               'Revert "Revert to using comma-delimited split"'):
-    ...     print(prepare(title) == title, prompt.called)
-    True False
-    True False
-    True False
-    True False
-
-    Surrounding whitespace is stripped from either kind of title, and the 
result printed.
-
-    >>> prepare(' Revert "[SPARK-1234][SQL] Fix" ')
-    Normalized title: Revert "[SPARK-1234][SQL] Fix"
-    'Revert "[SPARK-1234][SQL] Fix"'
-    >>> prepare(" [SPARK-1234][SQL] Fix ")
-    Normalized title: [SPARK-1234][SQL] Fix
-    '[SPARK-1234][SQL] Fix'
-
-    A bare Revert " is not a wrapper, so it is parsed as an ordinary title and 
rejected.
-
-    >>> print(prepare('Revert "'))
-    Malformed PR title: title must start with [SPARK-NNNNN], [MINOR], or 
[TRIVIAL]: 'Revert "'
-    >>> print(prepare('Reapply "'))
-    Malformed PR title: title must start with [SPARK-NNNNN], [MINOR], or 
[TRIVIAL]: 'Reapply "'
-    """,
-    "check_wrapped_title": """
-    A title whose innermost title still starts with Revert or Reapply, or a 
form of either,
-    is warned about with the direction it takes, and the merge asks for a 
confirmation.
-
-    >>> from contextlib import redirect_stdout
-    >>> from io import StringIO
-    >>> from unittest.mock import Mock, patch
-    >>> stop, confirm = Mock(side_effect=SystemExit), Mock()
-    >>> def check(title):
-    ...     stop.reset_mock()
-    ...     confirm.reset_mock()
-    ...     output = StringIO()
-    ...     with (
-    ...         patch.dict(check_wrapped_title.__globals__, fail=stop, 
continue_maybe=confirm),
-    ...         redirect_stdout(output),
-    ...     ):
-    ...         try:
-    ...             check_wrapped_title(title)
-    ...         except SystemExit:
-    ...             return "fail: " + stop.call_args.args[0]
-    ...     if confirm.called:
-    ...         confirm.assert_called_once_with("Merge with this title?")
-    ...         said = output.getvalue()
-    ...         shape = ("word" if "still starts with Revert or Reapply" in 
said
-    ...                  else "quote" if "starts with a quote." in said else 
"one word")
-    ...         line = said.splitlines()[1]
-    ...         assert line.startswith("  JIRA update") and said.count("JIRA 
update") == 1, said
-    ...         taken = ("a revert" if "a revert, which offers to remove fix 
versions" in line
-    ...                  else "a re-land" if "a re-land, which resolves the 
ticket or adds"
-    ...                  " fix versions" in line else line)
-    ...         return "confirm: %s (%s)" % (taken, shape)
-    ...     return output.getvalue() or "pass"
-    >>> for title in ('Revert "Revert "[SPARK-1234][SQL] Fix"',
-    ...               'Reapply "Revert "[SPARK-1234][SQL] Fix"',
-    ...               'Revert "Revert [SPARK-1234][SQL] Fix""',
-    ...               'Revert "revert [SPARK-1234][SQL] Fix"',
-    ...               'Revert "Reverted [SPARK-1234][SQL] Fix"',
-    ...               'Revert "Reapply "[SPARK-1234][SQL] Fix"',
-    ...               'Revert "Reapplied [SPARK-1234][SQL] Fix"',
-    ...               'Revert "Re-apply [SPARK-1234][SQL] Fix"',
-    ...               'Revert "Revert to using comma-delimited split"',
-    ...               'Reapply "Revert to using comma-delimited split"',
-    ...               'Revert "Revert "Revert "[SPARK-1234][SQL] Fix""'):
-    ...     print(check(title))
-    confirm: a revert (word)
-    confirm: a re-land (word)
-    confirm: a revert (word)
-    confirm: a revert (word)
-    confirm: a revert (word)
-    confirm: a revert (word)
-    confirm: a revert (word)
-    confirm: a revert (word)
-    confirm: a revert (word)
-    confirm: a re-land (word)
-    confirm: a re-land (word)
-
-    So is an innermost title that starts with a quote, or with one word and a 
quote, as a
-    doubled or misspelled wrapper would, including a subject that only quotes 
something
-    after its first word. A quote later in the title is not warned about.
-
-    >>> for title in ('Revert ""[SPARK-1234][SQL] Fix""',
-    ...               'Revert "Reaply "[SPARK-1234][SQL] Fix""',
-    ...               'Reapply "Revet "[SPARK-1234][SQL] Fix""',
-    ...               'Revert "Reaply"[SPARK-1234][SQL] Fix""',
-    ...               'Revert ""launch" scripts is more accurate terminology"',
-    ...               'Revert "Rename "jobs" to "applications""',
-    ...               'Revert "[SPARK-1234][SQL] Support "foo" in X"',
-    ...               'Revert "[SPARK-1234][SQL] Fix "foo""'):
-    ...     print(check(title))
-    confirm: a revert (quote)
-    confirm: a revert (one word)
-    confirm: a re-land (one word)
-    confirm: a revert (one word)
-    confirm: a revert (quote)
-    confirm: a revert (one word)
-    pass
-    pass
-
-    The whole warning, here for a misspelled wrapper:
-
-    >>> said = []
-    >>> with patch.dict(check_wrapped_title.__globals__,
-    ...                 print_error=lambda msg: said.append(msg) or 
print(msg)):
-    ...     print(check('Revert "Reaply "[SPARK-1234][SQL] Fix""'))
-    confirm: a revert (one word)
-    >>> print(said[0])  # doctest: +NORMALIZE_WHITESPACE
-    The innermost title of Revert "Reaply "[SPARK-1234][SQL] Fix"" starts with 
one word and
-    a quote.
-      JIRA update: a revert, which offers to remove fix versions (decided by 
the outer
-      wrappers alone; no JIRA id or skip tag is read from the innermost title).
-      If a quote is doubled or a wrapper misspelled, e.g. Revert ""..."" or 
Reaply "...", fix
-      it so that each layer is Revert "..." or Reapply "...", e.g. Reapply 
"[SPARK-N] ..."
-      for a revert of a revert.
-      If the subject only quotes something, as in Rename "jobs" to ... or 
"launch" ..., keep
-      the title, and enter the JIRA id at the prompt after the merge, or leave 
it blank to
-      skip.
-
-    When JIRA is disabled, the warning says to reconcile the ticket by hand 
instead of
-    entering an id at a prompt that will not come.
-
-    >>> said = []
-    >>> with patch.dict(check_wrapped_title.__globals__, jira_disabled=True,
-    ...                 print_error=lambda msg: said.append(msg) or 
print(msg)):
-    ...     print(check('Revert "Revert to using comma-delimited split"'))
-    confirm: a revert (word)
-    >>> print(said[0])  # doctest: +NORMALIZE_WHITESPACE
-    The innermost title of Revert "Revert to using comma-delimited split" 
still starts with
-    Revert or Reapply.
-      JIRA update (disabled for this run): would be a revert, which offers to 
remove fix
-      versions (decided by the outer wrappers alone; no JIRA id or skip tag is 
read from the
-      innermost title).
-      If a quote was dropped, or the innermost title is the subject of a 
revert commit, e.g.
-      Revert [SPARK-N] ..., retitle the PR so that each layer is Revert "..." 
or
-      Reapply "...", e.g. Reapply "[SPARK-N] ..." for a revert of a revert.
-      If it only starts with the word, as in Revert to using ..., keep the 
title, and
-      reconcile the ticket by hand after the merge.
-
-    An innermost title that is empty, or made only of quotes and spaces, 
fails. Balanced
-    wrappers and ordinary titles pass.
-
-    >>> for title in ('Revert ""', 'Revert " "', 'Reapply ""', 'Revert "Revert 
\"\"\"'):
-    ...     print(check(title))
-    fail: Empty title inside the Revert/Reapply wrappers of the PR title: 
Revert ""
-    fail: Empty title inside the Revert/Reapply wrappers of the PR title: 
Revert " "
-    fail: Empty title inside the Revert/Reapply wrappers of the PR title: 
Reapply ""
-    fail: Empty title inside the Revert/Reapply wrappers of the PR title: 
Revert "Revert \"\"\"
-    >>> for title in ('Revert \"\"\"\"', 'Revert \"\"\"', 'Revert "Revert 
\"\"\"\"',
-    ...               'Revert "" ""'):
-    ...     print(check(title).split(" inside ")[0])
-    fail: Empty title
-    fail: Empty title
-    fail: Empty title
-    fail: Empty title
-    >>> for title in ('Revert "[SPARK-1234][SQL] Fix"', 'Revert "Reapply 
"[SPARK-1234] Fix""',
-    ...               'Revert "SPARK-49004"', 'Revert "Fix"', 
'[SPARK-1234][SQL] Revert X',
-    ...               'Revert "[SPARK-1234][SQL] Revert X"'):
-    ...     print(check(title))
-    pass
-    pass
-    pass
-    pass
-    pass
-    pass
-    """,
-    "main_records": """
-    main() reports the picks cherry_pick hands to `record`, on a merge and on 
a backport of a
-    merged PR: the merge comment gets them in order and the JIRA update their 
branches, also
-    for picks recorded before a later pick ends the run. Each run takes the 
pairs the
-    cherry_pick stand-in records, one list per call (None ends the run), and 
returns the
-    pairs the merge comment receives, the branches the JIRA update receives, 
and the exit code.
-
-    >>> import sys
-    >>> from unittest.mock import Mock, patch
-    >>> footer = "\\n\\nBody\\n\\nCloses #1 from x/h.\\n\\nAuthored-by: X 
<x@x>"
-    >>> def run(calls, message=None):
-    ...     pr = {"url": "u", "title": "[SPARK-1][SQL] Fix", "draft": False, 
"body": "b",
-    ...           "base": {"ref": "master"}, "user": {"login": "x"}, "head": 
{"ref": "h"},
-    ...           "state": "open" if message is None else "closed", 
"mergeable": True}
-    ...     def get_json(url):
-    ...         if url.endswith("/branches"):
-    ...             return [{"name": b} for b in ("master", "branch-4.x", 
"branch-4.2")]
-    ...         if url.endswith("/pulls/1"):
-    ...             return pr
-    ...         if url.endswith("/users/x"):
-    ...             return {"name": "X", "email": "x@x", "id": 1}
-    ...         return []
-    ...     remaining = list(calls)
-    ...     def ask(prompt, *args, **kwargs):
-    ...         return "y" if remaining and "into another branch" in prompt 
else "n"
-    ...     def pick(*args, record, **kwargs):
-    ...         for pair in remaining.pop(0):
-    ...             if pair is None:
-    ...                 sys.exit(-1)  # a later pick ends the run
-    ...             record(pair)
-    ...     found = (None, None) if message is None else ("abc", message)
-    ...     comment, update = Mock(), Mock()
-    ...     with (
-    ...         patch.object(sys, "argv", ["merge_spark_pr.py", "1"]), 
patch("os.chdir"),
-    ...         patch.dict(main.__globals__, DRY_RUN_ENV=False, 
check_script_up_to_date=Mock(),
-    ...                    initialize_jira=Mock(), asf_jira=Mock(), 
jira_disabled=False,
-    ...                    clean_up=Mock(), 
get_current_ref=Mock(return_value="master"),
-    ...                    get_json=get_json, get_json_pages=get_json,
-    ...                    find_merge_commit=Mock(return_value=found),
-    ...                    git=Mock(), github=Mock(), 
check_linked_jira_issues=Mock(),
-    ...                    continue_maybe=Mock(), get_input=ask, 
merge_pr=Mock(return_value="abc"),
-    ...                    post_merge_comment=comment,
-    ...                    prompt_for_components=Mock(return_value=["CORE"]),
-    ...                    branches_with_merge_footer=Mock(return_value=[]),
-    ...                    default_pick_branch=Mock(return_value="branch-4.x"),
-    ...                    cherry_pick=pick, update_jira_for_pr=update, 
print=Mock()),
-    ...     ):
-    ...         code = None
-    ...         try:
-    ...             main()
-    ...         except SystemExit as e:
-    ...             code = e.code
-    ...     return (comment.call_args.args[1] if comment.called else None,
-    ...             update.call_args.args[2], code)
-
-    On a merge, the merged branch comes first and every recorded pick follows:
-
-    >>> run([[("branch-4.x", "d")], [("branch-4.2", "e")]])  # doctest: 
+NORMALIZE_WHITESPACE
-    ([('master', 'abc'), ('branch-4.x', 'd'), ('branch-4.2', 'e')],
-     ['master', 'branch-4.x', 'branch-4.2'], None)
-
-    A pick recorded before a later pick ends the run is still reported, and so 
is a merge
-    with no picks:
-
-    >>> run([[("branch-4.x", "d")], [None]])
-    ([('master', 'abc'), ('branch-4.x', 'd')], ['master', 'branch-4.x'], -1)
-    >>> run([])
-    ([('master', 'abc')], ['master'], None)
-
-    On a backport of a merged PR the comment holds only the picks, and the 
JIRA update also
-    the branch the PR merged into:
-
-    >>> message = "[SPARK-1][SQL] Fix" + footer
-    >>> run([[("branch-4.x", "d")], [("branch-4.2", "e")]], message)
-    ([('branch-4.x', 'd'), ('branch-4.2', 'e')], ['master', 'branch-4.x', 
'branch-4.2'], 0)
-    >>> run([[("branch-4.x", "d")], [None]], message)
-    ([('branch-4.x', 'd')], ['master', 'branch-4.x'], -1)
-    """,
-    "main_titles": """
-    main() hands the title that title_for_run() returns to the commit, the 
JIRA checks, and
-    the JIRA update: on a merge the prepared title, with a component entered 
at the prompt;
-    on a backport of a commit with the PR's merge footer, the committed 
subject, or, when
-    the current PR title would update JIRA differently and the committer 
answers y at the
-    question printed after the cherry-picks, right before the JIRA update, the 
current PR
-    title; and on a backport without that footer, the prepared current PR 
title. Every
-    GitHub, git, and JIRA call is mocked. Each run prints what it does, and 
returns the
-    title that update_jira_for_pr() receives, the title committed and checked 
against
-    JIRA (None on a backport), whether a component was asked for, and the exit 
code.
-
-    >>> import sys
-    >>> from unittest.mock import Mock, patch
-    >>> footer = "\\n\\nBody\\n\\nCloses #1 from x/h.\\n\\nAuthored-by: X 
<x@x>"
-    >>> def run(pr_title, message=None, answer="n"):
-    ...     pr = {"url": "u", "title": pr_title, "draft": False, "body": "b",
-    ...           "base": {"ref": "master"}, "user": {"login": "x"}, "head": 
{"ref": "h"},
-    ...           "state": "open" if message is None else "closed", 
"mergeable": True}
-    ...     requested = []
-    ...     def get_json(url):
-    ...         requested.append(url)
-    ...         if url.endswith("/branches"):
-    ...             return [{"name": "master"}, {"name": "branch-4.x"}]
-    ...         if url.endswith("/pulls/1"):
-    ...             return pr
-    ...         if url.endswith("/users/x"):
-    ...             return {"name": "X", "email": "x@x", "id": 1}
-    ...         return []
-    ...     def ask(prompt, *args, **kwargs):
-    ...         if prompt.startswith("Update JIRA from the current PR title"):
-    ...             print("asked: use the current PR title?")
-    ...             return answer
-    ...         if "into another branch" in prompt and message is not None:
-    ...             print("asked: pick another?")
-    ...         return "n"
-    ...     prompt = Mock(return_value=["CORE"])
-    ...     update = Mock(side_effect=lambda *args: print("JIRA update"))
-    ...     merge, check = Mock(return_value="abc"), Mock()
-    ...     pick = Mock(side_effect=lambda *a, **k: print("picked") or 
[("branch-4.x", "d")])
-    ...     found = (None, None) if message is None else ("abc", message)
-    ...     pick_default = Mock(return_value="branch-4.x")
-    ...     with (
-    ...         patch.object(sys, "argv", ["merge_spark_pr.py", "1"]), 
patch("os.chdir"),
-    ...         patch.dict(main.__globals__, DRY_RUN_ENV=False, 
check_script_up_to_date=Mock(),
-    ...                    initialize_jira=Mock(), asf_jira=Mock(), 
jira_disabled=False,
-    ...                    clean_up=Mock(), 
get_current_ref=Mock(return_value="master"),
-    ...                    get_json=get_json, get_json_pages=get_json,
-    ...                    find_merge_commit=Mock(return_value=found),
-    ...                    git=Mock(), github=Mock(), 
check_linked_jira_issues=check,
-    ...                    continue_maybe=Mock(), get_input=ask, 
merge_pr=merge,
-    ...                    post_merge_comment=Mock(), 
prompt_for_components=prompt,
-    ...                    branches_with_merge_footer=Mock(return_value=[]),
-    ...                    default_pick_branch=pick_default,
-    ...                    cherry_pick=pick, update_jira_for_pr=update, 
print=Mock(),
-    ...                    print_error=lambda msg: print(msg.splitlines()[0])),
-    ...     ):
-    ...         code = None
-    ...         try:
-    ...             main()
-    ...         except SystemExit as e:
-    ...             code = e.code
-    ...     committed = merge.call_args.args[2] if merge.called else None
-    ...     assert committed == (check.call_args.args[1] if check.called else 
None)
-    ...     assert all(c.args[0] == ["branch-4.x"] for c in 
pick_default.call_args_list)
-    ...     # A merge reads no events, and a backport reads neither commits 
nor the author.
-    ...     unused = ("/issues/1/events",) if message is None else 
("/pulls/1/commits", "/users/x")
-    ...     assert not [url for url in requested if url.endswith(unused)], 
requested
-    ...     return update.call_args.args[1], committed, prompt.called, code
-
-    A merge commits, checks, and updates JIRA from the prepared title:
-
-    >>> run("[SPARK-1] Fix")
-    JIRA update
-    ('[SPARK-1][CORE] Fix', '[SPARK-1][CORE] Fix', True, None)
-
-    A merge runs the wrapper check, which warns here:
-
-    >>> run('Revert "Revert to using X"')
-    The innermost title of Revert "Revert to using X" still starts with Revert 
or Reapply.
-    JIRA update
-    ('Revert "Revert to using X"', 'Revert "Revert to using X"', False, None)
-
-    A backport of a commit with the PR's merge footer reads the committed 
subject without
-    preparing the current PR title, whether the PR title is the same, differs 
only in how a
-    tag is spelled, or also lacks the component entered at the merge prompt:
-
-    >>> run("[SPARK-1][SQL] Fix", "[SPARK-1][SQL] Fix" + footer)
-    picked
-    asked: pick another?
-    JIRA update
-    ('[SPARK-1][SQL] Fix', None, False, 0)
-    >>> run("[SPARK-1][CORE][TESTS] Fix", "[SPARK-1][CORE][TEST] Fix" + footer)
-    picked
-    asked: pick another?
-    JIRA update
-    ('[SPARK-1][CORE][TEST] Fix', None, False, 0)
-    >>> run("[SPARK-1][TESTS] Fix", "[SPARK-1][CORE][TEST] Fix" + footer)
-    picked
-    asked: pick another?
-    JIRA update
-    ('[SPARK-1][CORE][TEST] Fix', None, False, 0)
-
-    For a PR title edited to another id since, the notice and the question 
come after the
-    cherry-picks, right before the JIRA update:
-
-    >>> run("[SPARK-2][SQL] Fix", "[SPARK-1][SQL] Fix" + footer)
-    picked
-    asked: pick another?
-    The merge commit subject and the current PR title would update JIRA 
differently:
-    asked: use the current PR title?
-    JIRA update
-    ('[SPARK-1][SQL] Fix', None, False, 0)
-    >>> run("[SPARK-2][SQL] Fix", "[SPARK-1][SQL] Fix" + footer, answer="y")
-    picked
-    asked: pick another?
-    The merge commit subject and the current PR title would update JIRA 
differently:
-    asked: use the current PR title?
-    JIRA update
-    ('[SPARK-2][SQL] Fix', None, False, 0)
-
-    A backport does not run the wrapper check, which is for titles about to be 
committed,
-    even when it prepares the current PR title for a commit without the PR's 
merge footer:
-
-    >>> wrapped = 'Revert "Revert to using comma-delimited split"'
-    >>> run(wrapped, wrapped + footer)
-    picked
-    asked: pick another?
-    JIRA update
-    ('Revert "Revert to using comma-delimited split"', None, False, 0)
-    >>> run(wrapped, "[SPARK-3][SQL] Other" + footer.replace("#1", "#3"))
-    picked
-    asked: pick another?
-    JIRA update
-    ('Revert "Revert to using comma-delimited split"', None, False, 0)
-
-    A backport of a commit without the PR's merge footer, e.g. another PR's 
merge commit
-    linked to the PR's closed event, prepares the current PR title, as before:
-
-    >>> run("[SPARK-2] Fix", "[SPARK-3][SQL] Other" + footer.replace("#1", 
"#3"))
-    picked
-    asked: pick another?
-    JIRA update
-    ('[SPARK-2][CORE] Fix', None, True, 0)
-    """,
-    "check_linked_jira_issues": """
-    Only the leading ids are fetched and checked, so an Epic that the title 
body mentions
-    neither blocks the merge nor asks for confirmation.
-
-    >>> from contextlib import redirect_stdout
-    >>> from io import StringIO
-    >>> from unittest.mock import Mock, call, patch
-    >>> def issue(issue_type):
-    ...     i = Mock()
-    ...     i.fields.issuetype.name = issue_type
-    ...     return i
-    >>> client = Mock()
-    >>> client.issue.side_effect = {
-    ...     "SPARK-60328": issue("Sub-task"), "SPARK-60329": issue("Bug"),
-    ...     "SPARK-34261": issue("Epic"), "SPARK-34262": 
issue("Umbrella")}.__getitem__
-    >>> verify = Mock(return_value="")
-    >>> stop = Mock(side_effect=SystemExit)
-    >>> def check(title, answers=("y",)):
-    ...     for m in (client, verify, stop):
-    ...         m.reset_mock()
-    ...     with (
-    ...         patch.dict(check_linked_jira_issues.__globals__, 
asf_jira=client,
-    ...                    print_jira_issue_summary=Mock(), 
format_jira_verification=verify,
-    ...                    fail=stop),
-    ...         patch("builtins.input", side_effect=answers),
-    ...         redirect_stdout(StringIO()),
-    ...     ):
-    ...         check_linked_jira_issues("123", title)
-    >>> check("[SPARK-60328][SQL][TESTS] Use a unique jar copy in the 
HiveDDLSuite "
-    ...       "SPARK-34261 test")
-    >>> client.issue.call_args_list
-    [call('SPARK-60328')]
-    >>> stop.assert_not_called()
-    >>> verify.call_args.args[2]
-    'SPARK-60328'
-
-    Each leading id is confirmed, and declining one aborts the merge.
-
-    >>> check("[SPARK-60328][SPARK-60329][SQL] Fix", answers=("y", "y"))
-    >>> [c.args[2] for c in verify.call_args_list]
-    ['SPARK-60328', 'SPARK-60329']
-    >>> stop.assert_not_called()
-    >>> try:
-    ...     check("[SPARK-60328][SQL] Fix", answers=("n",))
-    ... except SystemExit:
-    ...     pass
-    >>> stop.call_args.args[0].startswith("Aborting: SPARK-60328 does not 
match PR #123.")
-    True
-    >>> try:
-    ...     check("[SPARK-60328][SQL] Fix", answers=("",))
-    ... except SystemExit:
-    ...     pass
-    >>> stop.call_count
-    1
-
-    A ticket that cannot be fetched is skipped.
-
-    >>> check("[SPARK-1][SQL] Fix")
-    >>> client.issue.call_args_list
-    [call('SPARK-1')]
-    >>> verify.assert_not_called()
-    >>> stop.assert_not_called()
-    >>> try:
-    ...     check("[SPARK-1][SPARK-34261][SQL] Fix")
-    ... except SystemExit:
-    ...     pass
-    >>> "SPARK-34261 (Epic)" in stop.call_args.args[0]
-    True
-
-    When JIRA was disabled for this run, nothing is fetched or confirmed.
-
-    >>> client.reset_mock()
-    >>> output = StringIO()
-    >>> with (
-    ...     patch.dict(check_linked_jira_issues.__globals__, asf_jira=client, 
jira_disabled=True),
-    ...     redirect_stdout(output),
-    ... ):
-    ...     check_linked_jira_issues("123", "[SPARK-60328][SQL] Fix")
-    >>> client.issue.assert_not_called()
-    >>> "skipping the Epic/Umbrella check" in output.getvalue()
-    True
-
-    Leading Epic and Umbrella tickets block the merge, all listed at once, 
before any
-    confirmation.
-
-    >>> try:
-    ...     check("[SPARK-34261][SPARK-60328][SPARK-34262][SQL] Fix")
-    ... except SystemExit:
-    ...     pass
-    >>> msg = stop.call_args.args[0]
-    >>> "SPARK-34261 (Epic), SPARK-34262 (Umbrella)" in msg
-    True
-    >>> verify.assert_not_called()
-
-    A FOLLOWUP tag suppresses the similarity check inside Revert/Reapply 
wrappers and
-    under the FOLLOW-UP alias too, while a title without the tag is still 
checked.
-
-    >>> for title in ('[SPARK-60328][SQL][FOLLOWUP] Fix', 'Revert 
"[SPARK-60328][SQL] Fix"',
-    ...               '[SPARK-60328][SQL] Fix FOLLOWUP handling',
-    ...               'Revert "[SPARK-60328][SQL][FOLLOW-UP] Fix"',
-    ...               'Reapply "[SPARK-60328][FOLLOWUP][SQL][MINOR] Fix"'):
-    ...     check(title)
-    ...     print(verify.call_args.kwargs["is_followup"])
-    True
-    False
-    False
-    True
-    True
-    """,
-    "reconcile_jira_affects_versions": """
-    Blank input accepts the suggested version and appends it to the existing 
versions:
-
-    >>> from contextlib import redirect_stdout
-    >>> from io import StringIO
-    >>> from types import SimpleNamespace
-    >>> from unittest.mock import Mock, patch
-    >>> issue = SimpleNamespace(
-    ...     key="SPARK-1", 
fields=SimpleNamespace(versions=[SimpleNamespace(name="5.0.0")]))
-    >>> available = {"5.0.0", "4.4.0"}
-    >>> writer = Mock(spec=Jira)
-    >>> with (
-    ...     patch.dict(reconcile_jira_affects_versions.__globals__, 
jira_ops=writer),
-    ...     patch("builtins.input", side_effect=["", "", KeyboardInterrupt]) 
as user_input,
-    ...     redirect_stdout(StringIO()),
-    ... ):
-    ...     reconcile_jira_affects_versions(issue, ["4.4.0"], available, 
["4.4.0"])
-    >>> writer.update_affects_versions.assert_called_once_with(issue, 
["5.0.0", "4.4.0"])
-    >>> user_input.call_count
-    2
-
-    Explicitly skipping an eligible suggestion leaves the JIRA writer 
untouched:
-
-    >>> writer.reset_mock()
-    >>> with (
-    ...     patch.dict(reconcile_jira_affects_versions.__globals__, 
jira_ops=writer),
-    ...     patch("builtins.input", side_effect=["skip", KeyboardInterrupt]) 
as user_input,
-    ...     redirect_stdout(StringIO()),
-    ... ):
-    ...     reconcile_jira_affects_versions(issue, ["4.4.0"], available, 
["4.4.0"])
-    >>> writer.mock_calls
-    []
-    >>> user_input.call_count
-    1
-    """,
-    "jira_is_live": """
-    The probe classifies what urlopen hit: a response -- even a 4xx -- means 
live, a 5xx or
-    any non-HTTP error (DNS failure, connection refused, TLS error) means 
dead, and the
-    reason names it so the committer can tell an ASF outage from a local 
network problem.
-
-    >>> from unittest.mock import MagicMock, Mock, patch
-    >>> from urllib.error import HTTPError, URLError
-    >>> import socket
-    >>> def probe(error=None):
-    ...     opener = MagicMock() if error is None else Mock(side_effect=error)
-    ...     with patch.dict(jira_is_live.__globals__, urlopen=opener):
-    ...         return jira_is_live()
-    >>> probe()
-    (True, None)
-    >>> probe(HTTPError("https://issues.apache.org/jira";, 404, "Not Found", 
{}, None))
-    (True, None)
-    >>> probe(HTTPError("https://issues.apache.org/jira";, 503, "Service 
Unavailable", {}, None))
-    (False, 'server answered HTTP 503')
-    >>> probe(URLError("connection refused"))
-    (False, 'URLError: <urlopen error connection refused>')
-    >>> live, reason = probe(socket.timeout("timed out"))
-    >>> live, "timed out" in reason
-    (False, True)
-    """,
-    "initialize_jira": """
-    An unreachable or unhealthy JIRA disables this run's JIRA steps without 
touching the
-    client library or credentials, which are only checked once the probe says 
JIRA is live.
+def run_prmerge_tests() -> bool:
+    """
+    Run the unit tests in ``dev/prmerge/tests``. Quiet when they pass.
 
-    >>> from contextlib import redirect_stdout
-    >>> from io import StringIO
-    >>> from unittest.mock import Mock, patch
-    >>> def initialize_with_probe(result):
-    ...     output = StringIO()
-    ...     with (
-    ...         patch.dict(initialize_jira.__globals__, 
jira_is_live=Mock(return_value=result)),
-    ...         redirect_stdout(output),
-    ...     ):
-    ...         initialize_jira()
-    ...         g = initialize_jira.__globals__
-    ...         return (g["jira_disabled"], g["asf_jira"]), output.getvalue()
-    >>> state, output = initialize_with_probe((False, "server answered HTTP 
503"))
-    >>> state
-    (True, None)
-    >>> "JIRA is unreachable or unhealthy (server answered HTTP 503)" in output
-    True
-    >>> "disabling all JIRA steps for this merge" in output
-    True
-    """,
-    "jira_ids_to_verify": """
-    The leading ids of the title feed the Epic/Umbrella and match checks; with 
JIRA disabled
-    they are dropped -- with a reminder naming them, or the generic fallback 
-- so the checks
-    are skipped rather than failing on asf_jira being None.
+    A missing suite refuses the merge: an empty run would otherwise look like 
a pass.
+    """
+    import io
+    import unittest
+
+    # Python puts the script's real directory on sys.path, so resolve symlinks 
here too.
+    script_dir = os.path.dirname(os.path.realpath(__file__))
+    start_dir = os.path.join(script_dir, "prmerge", "tests")
+    not_found = "prmerge tests were not found; refusing to merge.\n"
+    hint = (
+        "If dev/prmerge/ is behind master, update it with the script:\n"
+        f"    git fetch {PUSH_REMOTE_NAME} master && "
+        f"git checkout --no-overlay {PUSH_REMOTE_NAME}/master -- "
+        "dev/merge_spark_pr.py dev/prmerge\n"
+    )
+    # discover() raises ImportError when this directory is missing.
+    if not os.path.isdir(start_dir):

Review Comment:
   This is such a contrived scenario that I don't think is worth addressing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to