Skip to content

Commit 9f6cc29

Browse files
style: format setup preview tests with Black
Amp-Thread-ID: https://ampcode.com/threads/T-01a17775-d386-7387-88ab-c14a99ed558e Co-authored-by: Amp <amp@ampcode.com>
1 parent cf89b25 commit 9f6cc29

3 files changed

Lines changed: 73 additions & 17 deletions

File tree

‎tests/test_setup_previews.py‎

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,48 @@
1616
NOTIFY = ROOT / "scripts" / "action" / "notify-setup-ready.sh"
1717

1818
PULLS = {
19-
"412": {"state": "open", "head": {"repo": {"full_name": "owner/repo"}, "sha": "h412"}, "base": {"ref": "main", "sha": "t"}, "title": "Retry failed webhooks"},
20-
"409": {"state": "open", "head": {"repo": {"full_name": "owner/repo"}, "sha": "h409"}, "base": {"ref": "main", "sha": "t"}, "title": "Split ledger"},
21-
"401": {"state": "open", "head": {"repo": {"full_name": "owner/repo"}, "sha": "h401"}, "base": {"ref": "main", "sha": "t"}, "title": "Bump SDK"},
22-
"400": {"state": "open", "head": {"repo": {"full_name": "owner/repo"}, "sha": "h400"}, "base": {"ref": "main", "sha": "t"}, "title": "Fourth"},
23-
"377": {"state": "open", "head": {"repo": {"full_name": "someone/fork"}, "sha": "h377"}, "base": {"ref": "main", "sha": "t"}, "title": "From a fork"},
24-
"350": {"state": "closed", "head": {"repo": {"full_name": "owner/repo"}, "sha": "h350"}, "base": {"ref": "main", "sha": "t"}, "title": "Closed"},
25-
"340": {"state": "open", "head": {"repo": {"full_name": "owner/repo"}, "sha": "h340"}, "base": {"ref": "release", "sha": "t"}, "title": "Other branch"},
19+
"412": {
20+
"state": "open",
21+
"head": {"repo": {"full_name": "owner/repo"}, "sha": "h412"},
22+
"base": {"ref": "main", "sha": "t"},
23+
"title": "Retry failed webhooks",
24+
},
25+
"409": {
26+
"state": "open",
27+
"head": {"repo": {"full_name": "owner/repo"}, "sha": "h409"},
28+
"base": {"ref": "main", "sha": "t"},
29+
"title": "Split ledger",
30+
},
31+
"401": {
32+
"state": "open",
33+
"head": {"repo": {"full_name": "owner/repo"}, "sha": "h401"},
34+
"base": {"ref": "main", "sha": "t"},
35+
"title": "Bump SDK",
36+
},
37+
"400": {
38+
"state": "open",
39+
"head": {"repo": {"full_name": "owner/repo"}, "sha": "h400"},
40+
"base": {"ref": "main", "sha": "t"},
41+
"title": "Fourth",
42+
},
43+
"377": {
44+
"state": "open",
45+
"head": {"repo": {"full_name": "someone/fork"}, "sha": "h377"},
46+
"base": {"ref": "main", "sha": "t"},
47+
"title": "From a fork",
48+
},
49+
"350": {
50+
"state": "closed",
51+
"head": {"repo": {"full_name": "owner/repo"}, "sha": "h350"},
52+
"base": {"ref": "main", "sha": "t"},
53+
"title": "Closed",
54+
},
55+
"340": {
56+
"state": "open",
57+
"head": {"repo": {"full_name": "owner/repo"}, "sha": "h340"},
58+
"base": {"ref": "release", "sha": "t"},
59+
"title": "Other branch",
60+
},
2661
}
2762

2863

@@ -90,7 +125,10 @@ def _entry(self, n: int) -> dict:
90125
def test_the_listed_pull_requests_are_previewed_in_order(self) -> None:
91126
out = self._run("Adds CodeBoarding.\n\n<!-- codeboarding:preview 412,409 -->\n")
92127
self.assertEqual(out, {"count": "2", "prs": "412,409"})
93-
self.assertEqual(self._entry(1), {"pr_number": "412", "head_sha": "h412", "merge_base_sha": "mb-h412", "title": "Retry failed webhooks"})
128+
self.assertEqual(
129+
self._entry(1),
130+
{"pr_number": "412", "head_sha": "h412", "merge_base_sha": "mb-h412", "title": "Retry failed webhooks"},
131+
)
94132
self.assertEqual(self._entry(2)["pr_number"], "409")
95133

96134
def test_forks_closed_and_other_branches_are_skipped_and_the_list_is_capped(self) -> None:
@@ -135,7 +173,9 @@ def setUp(self) -> None:
135173
(self.base_dir / "analysis.json").write_text('{"components": []}')
136174
self.review_dir = self.root / "review-artifact"
137175
self.review_dir.mkdir()
138-
(self.review_dir / "metadata.json").write_text(json.dumps({"base_artifact": "cb-base-Z", "base_artifact_id": "77"}))
176+
(self.review_dir / "metadata.json").write_text(
177+
json.dumps({"base_artifact": "cb-base-Z", "base_artifact_id": "77"})
178+
)
139179

140180
# The action tree with the engine and renderer stubbed; the packager is the real one.
141181
action = self.action = self.root / "action"
@@ -150,7 +190,9 @@ def setUp(self) -> None:
150190
encoding="utf-8",
151191
)
152192
analyze.chmod(0o755)
153-
(action / "scripts" / "diff_to_mermaid.py").write_text('print(\'{"n_changed": 1, "analysed_files_changed": 1}\')\n')
193+
(action / "scripts" / "diff_to_mermaid.py").write_text(
194+
'print(\'{"n_changed": 1, "analysed_files_changed": 1}\')\n'
195+
)
154196

155197
self.preview_dir = self.root / "codeboarding-preview"
156198
self.preview_dir.mkdir()
@@ -159,8 +201,16 @@ def tearDown(self) -> None:
159201
self.temp_dir.cleanup()
160202

161203
def _run(self, pr_head: str | None = None) -> dict[str, str]:
162-
(self.preview_dir / "1.json").write_text(json.dumps(
163-
{"pr_number": "412", "head_sha": pr_head or self.pr_head, "merge_base_sha": self.fork_point, "title": "Retry failed webhooks"}))
204+
(self.preview_dir / "1.json").write_text(
205+
json.dumps(
206+
{
207+
"pr_number": "412",
208+
"head_sha": pr_head or self.pr_head,
209+
"merge_base_sha": self.fork_point,
210+
"title": "Retry failed webhooks",
211+
}
212+
)
213+
)
164214
output = self.root / "output"
165215
output.write_text("")
166216
subprocess.run(
@@ -233,9 +283,14 @@ def test_the_email_links_the_first_reviewed_pull_request(self) -> None:
233283
[str(NOTIFY)],
234284
env={
235285
"PATH": f"{root / 'bin'}:{os.environ['PATH']}",
236-
"REPOSITORY": "owner/repo", "PR_NUMBER": "418", "PR_AUTHOR": "maria-k",
237-
"HEAD_REF": "codeboarding/setup-action", "BASE_REF": "main",
238-
"FIRST_PR": "412", "FIRST_TITLE": "Retry failed webhooks", "PREVIEW_PRS": "412,409,401",
286+
"REPOSITORY": "owner/repo",
287+
"PR_NUMBER": "418",
288+
"PR_AUTHOR": "maria-k",
289+
"HEAD_REF": "codeboarding/setup-action",
290+
"BASE_REF": "main",
291+
"FIRST_PR": "412",
292+
"FIRST_TITLE": "Retry failed webhooks",
293+
"PREVIEW_PRS": "412,409,401",
239294
},
240295
check=True,
241296
capture_output=True,

‎tests/test_setup_ready_notice.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_a_bot_author_is_not_mentioned(self) -> None:
6868
def test_the_step_runs_only_after_a_posted_review_on_the_setup_branch(self) -> None:
6969
action = (ROOT / "action.yml").read_text(encoding="utf-8")
7070
start = action.index(" - name: Tell the setup PR's author the map is ready")
71-
step = action[start:action.index("\n - name:", start + 1)]
71+
step = action[start : action.index("\n - name:", start + 1)]
7272
self.assertGreater(start, action.index(" - name: Post review comment"))
7373
condition = next(line for line in step.splitlines() if line.strip().startswith("if:"))
7474
self.assertIn("steps.review_comment.outcome == 'success'", condition)

‎tests/test_with_auth.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def test_every_step_but_the_last_of_a_mode_keeps_credentials(self) -> None:
6060
# other pull requests; elsewhere it is the last analysis and removes them.
6161
keeps = "KEEP_AUTH: 'true'" in step or (
6262
step.startswith("Analyze pull request")
63-
and "KEEP_AUTH: ${{ github.event_name == 'pull_request' && github.head_ref == 'codeboarding/setup-action' }}" in step
63+
and "KEEP_AUTH: ${{ github.event_name == 'pull_request' && github.head_ref == 'codeboarding/setup-action' }}"
64+
in step
6465
)
6566
self.assertTrue(keeps, f"{mode}: {step.splitlines()[0]} consumes the credentials")
6667
self.assertNotIn("KEEP_AUTH", steps[-1], f"{mode}: the last analysis step must remove them")

0 commit comments

Comments
 (0)