Skip to content

Commit e7828b6

Browse files
committed
chore(golden): satisfy ruff PLR2004 + black on new fix-up tests
Pull magic numbers (rename change count, argparse usage exit code) into named constants, and let black collapse the adjacent-string formatting on the new parser tests.
1 parent 6f6959b commit e7828b6

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

tests/golden/test_check_semver_bump.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
from tests.golden import check_semver_bump as csb
88

9+
# A rename emits one D + one A change.
10+
_RENAME_CHANGE_COUNT = 2
11+
912

1013
def test_no_changes_passes():
1114
rc, msg = csb.check(
@@ -80,23 +83,21 @@ def test_parser_rename_emits_delete_plus_add(monkeypatch):
8083
split into a deletion of OLD and an addition of NEW so the gate sees
8184
the source go away."""
8285
fake_diff = (
83-
"R100\ttests/golden/templates/x/old/expected.build.yaml"
84-
"\ttests/golden/templates/x/new/expected.build.yaml\n"
86+
"R100\ttests/golden/templates/x/old/expected.build.yaml" "\ttests/golden/templates/x/new/expected.build.yaml\n"
8587
)
8688
monkeypatch.setattr(csb.subprocess, "check_output", lambda *a, **kw: fake_diff)
8789
changes = csb._git_changed_files("base", "head")
8890
assert csb.Change("tests/golden/templates/x/old/expected.build.yaml", "D") in changes
8991
assert csb.Change("tests/golden/templates/x/new/expected.build.yaml", "A") in changes
90-
assert len(changes) == 2
92+
assert len(changes) == _RENAME_CHANGE_COUNT
9193

9294

9395
def test_parser_copy_treated_as_addition_only(monkeypatch):
9496
"""A `C<score>\\tOLD\\tNEW` line means the source still exists, only
9597
the new target is added. The gate must classify this as A only — not
9698
let it silently bypass via an unrecognized "C" status."""
9799
fake_diff = (
98-
"C100\ttests/golden/templates/x/old/expected.build.yaml"
99-
"\ttests/golden/templates/x/new/expected.build.yaml\n"
100+
"C100\ttests/golden/templates/x/old/expected.build.yaml" "\ttests/golden/templates/x/new/expected.build.yaml\n"
100101
)
101102
monkeypatch.setattr(csb.subprocess, "check_output", lambda *a, **kw: fake_diff)
102103
changes = csb._git_changed_files("base", "head")
@@ -112,8 +113,7 @@ def test_copy_of_existing_pin_does_not_bypass_gate(monkeypatch):
112113
addition — feeding only A's through `check()` correctly returns 0,
113114
but the path must NOT be silently dropped."""
114115
fake_diff = (
115-
"C100\ttests/golden/templates/x/old/expected.build.yaml"
116-
"\ttests/golden/templates/x/new/expected.build.yaml\n"
116+
"C100\ttests/golden/templates/x/old/expected.build.yaml" "\ttests/golden/templates/x/new/expected.build.yaml\n"
117117
)
118118
monkeypatch.setattr(csb.subprocess, "check_output", lambda *a, **kw: fake_diff)
119119
changes = csb._git_changed_files("base", "head")

tests/golden/test_update_goldens.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
REPO_CASES = Path(__file__).parent / "templates"
1111

12+
# argparse's parser.error() exits with status 2 (Unix convention for usage error).
13+
_ARGPARSE_USAGE_ERROR = 2
14+
1215

1316
@pytest.fixture
1417
def isolated_corpus(tmp_path, monkeypatch):
@@ -110,6 +113,6 @@ def test_check_and_diff_are_mutually_exclusive(capsys):
110113
checks."""
111114
with pytest.raises(SystemExit) as excinfo:
112115
update_goldens.main(["--check", "--diff"])
113-
assert excinfo.value.code == 2 # argparse parser.error exits 2
116+
assert excinfo.value.code == _ARGPARSE_USAGE_ERROR
114117
err = capsys.readouterr().err
115118
assert "--check and --diff are mutually exclusive" in err

0 commit comments

Comments
 (0)