Skip to content

tests/test_naming_policy.py: bind the tuple before comparing it in test_every_classified_name_keeps_its_exact_answer, so Sonar's assertion-order rule reads the actual value as a name instead of a literal tuple display #130

Closed

Description

@brettheap

Lane: openreposhape-2 (openRepoShape-2)

What is wrong

SonarCloud rule python:S3415 ("Unify assertion argument order in this
file; both 'actual first' and 'expected first' conventions are used")
is OPEN against tests/test_naming_policy.py (issue key
AaCLcrLfNM_GaF89pHsJ, re-analysed at commit 50d4078 on
2026-09-12T01:10:34Z). Sonar's own flow data names 130+ sites as
"Actual value first" (the file's dominant, pytest-idiomatic convention:
the computed/actual value on the left of ==, the expected value on
the right) and exactly one site as "Expected value first" — the outlier
tripping the rule:

tests/test_naming_policy.py:1285

assert (found.family, found.role, found.also_matches) == expected

Sonar's heuristic reads the parenthesised tuple display on the left as
a literal (because it is built with tuple syntax) and the bare name
expected on the right as the actual value. That reading is
backwards for this line: found is the value the classifier under
test produced, so (found.family, found.role, found.also_matches) is
the actual value, and expected (the parametrized table entry from
KEEPS_ITS_ANSWER) is what the test expects it to equal — the line
already asserts in the file's dominant order semantically, but its
syntax (a tuple display, not a bare name) is what fools the rule.

What would fix it

Bind the tuple to a name before comparing it, so the left-hand side of
== reads as a name (satisfying Sonar's rule) and — independently of
Sonar — the binding is worth having on its own merits: it names what
the three attributes are being compared as, exactly what expected
already does for the other side, in the test whose sole job is
asserting that comparison.

def test_every_classified_name_keeps_its_exact_answer(policy, name, role, pins,
                                                      expected):
    """The property the README states, as a table rather than as a claim."""
    found = policy.classify(name, role, set(pins))
    if expected is None:
        assert found is None, f"{name} unexpectedly classified as {found}"
        return
    assert found is not None, f"{name} classified as nothing"
    actual = (found.family, found.role, found.also_matches)
    assert actual == expected

No other line in the file needs touching — a full manual pass over
every assert … == … site (133 total, including wrapped continuations)
found no other minority-order site; this is the only one Sonar's flow
names.

Activity

  1. brettheap commented on Sep 12, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-12T01:18Z) CLAIMED — session 3b1ab8cf, on Brett Heap's word 'go, fan out on all of it' (relayed correction/task from the orchestrator). Branch chore/naming-tests-assertion-argument-order, worktree ~/projects/openRepoShape--naming-assert-order on Eagle, from origin/main 50d4078. Scope: bind the tuple to actual before the comparison in test_every_classified_name_keeps_its_exact_answer (tests/test_naming_policy.py:1285) — the one line python:S3415 flags — no other line touched.

  2. brettheap commented on Sep 12, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-12T01:29Z) PULL REQUEST OPEN: #131 (head 30c07ef).

  3. brettheap commented on Sep 12, 2026

    @brettheap
    ContributorAuthor

    (lane openreposhape-2 (openRepoShape-2), 2026-09-12T01:50:24Z) MERGED — #131 → d682127 (squash), on Brett Heap's word 'go, fan out on all of it, hold the doctor refactor'. tests/test_naming_policy.py: the classifier result tuple is bound to 'actual' before the assert against 'expected', so Sonar's S3415 assertion-order rule stops reading the tuple display of three actual attributes as a literal on the expected side; the last Sonar row in tests/, nothing asserted changes; Copilot 'Approval recommended' 0 findings; 1136 passed / 1 skipped. Object complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions