Skip to content

tests/test_naming_policy.py: bind the compared tuple to a name before asserting it, so Sonar's assertion-order rule stops misreading the literal-looking display as the expected side (#130) - #131

Merged
brettheap merged 1 commit into
mainfrom
chore/naming-tests-assertion-argument-order
Sep 12, 2026
Merged

brettheap merged 1 commit into
mainfrom
chore/naming-tests-assertion-argument-order

Conversation

@brettheap

@brettheap brettheap commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openreposhape-2 (openRepoShape-2)
Claim: #130 (comment)

Closes #130.

What was wrong

SonarCloud python:S3415 was OPEN against tests/test_naming_policy.py
(issue AaCLcrLfNM_GaF89pHsJ, re-analysed at 50d4078 on
2026-09-12T01:10:34Z), naming one line as "Expected value first" against
130+ "Actual value first" sites elsewhere in the file (the dominant,
pytest-idiomatic convention: actual/computed value on the left of ==,
expected value on the right):

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, and the bare name expected on the right as the actual value
— backwards for this line. found is the value the classifier under
test produced; (found.family, found.role, found.also_matches) is the
actual value, and expected is the row from the KEEPS_ITS_ANSWER
parametrize table the test expects it to equal. The line already asserts
in the file's dominant order semantically; only its syntax fooled the
rule.

A full manual pass over every assert … == … site in the file (133
total, including wrapped continuations) found no other minority-order
site.

What landed

tests/test_naming_policy.py, test_every_classified_name_keeps_its_exact_answer:

     assert found is not None, f"{name} classified as nothing"
-    assert (found.family, found.role, found.also_matches) == expected
+    actual = (found.family, found.role, found.also_matches)
+    assert actual == expected

Binding the tuple to actual fixes Sonar's misreading (the left side is
now a bare name) and, independent of Sonar, names what the three
attributes are being compared as — the same way expected already names
the other side. No pinned/digest-copied file is touched.

How it was proven

  • python3 -m pytest -q tests/test_naming_policy.py — 162 passed.
  • Full suite, foreground, two bounded chunks:
    • tests/test_[a-m]*.py — 366 passed, 1 skipped (the known flake).
    • tests/test_[n-z]*.py — 770 passed.
    • Total: 1136 passed, 1 skipped, matching the expected baseline.

🤖 Generated with Claude Code

Summary by Sourcery

Enhancements:

  • Clarify the compared classifier result as an explicitly named actual value so assertion-order analysis correctly recognizes the test’s comparison semantics.

… asserting it, so Sonar's assertion-order rule stops misreading the literal-looking display as the expected side (#130)

python:S3415 was OPEN against one line in this file:
`assert (found.family, found.role, found.also_matches) == expected`
in `test_every_classified_name_keeps_its_exact_answer`. The rule's
heuristic reads a parenthesised tuple display as a literal, so it read
this line as "expected first" even though `found` is the classifier's
actual output and `expected` is the parametrized table's expected
value — the file's dominant, pytest-idiomatic order, already correct
in substance. Naming the tuple `actual` before the comparison fixes
the rule's misreading and, independent of Sonar, says in the code what
the three attributes are being compared as, the same way `expected`
already names the other side.

A full manual pass over every `assert … == …` site in the file (133
total, wrapped continuations included) found no other minority-order
site, so no other line changes.

Lane: openreposhape-2 (openRepoShape-2)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 12, 2026 01:29
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 15 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@sourcery-ai

sourcery-ai Bot commented Sep 12, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR updates one assertion in the exact-answer naming-policy test by naming the computed tuple actual before comparing it with expected, preventing SonarCloud from misidentifying the assertion order while preserving behavior.

File-Level Changes

Change Details Files
Make the assertion’s computed tuple explicit as the actual value to satisfy Sonar’s assertion-order heuristic without changing test semantics.
  • Assign the classified result tuple to actual.
  • Assert the named actual value against the parametrized expected value.
tests/test_naming_policy.py

Assessment against linked issues

Issue Objective Addressed Explanation
#130 Bind the classified result tuple to a named variable before comparing it with the expected value, so SonarCloud correctly recognizes the assertion as actual-first. ✅
#130 Preserve the test's intended semantic comparison between the classifier's family, role, and aliases and the parametrized expected answer, while improving readability by naming the actual tuple. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused change has no unresolved issues and preserves tested behavior.

Pull request overview

This test-only PR fixes a SonarCloud assertion-order false positive by naming the classifier tuple before comparison.

Changes:

  • Binds the tuple to actual.
  • Preserves the existing assertion behavior.
File summaries
File Description
tests/test_naming_policy.py Names the classifier result tuple before asserting against expected.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@brettheap
brettheap merged commit d682127 into main Sep 12, 2026
6 checks passed
@brettheap
brettheap deleted the chore/naming-tests-assertion-argument-order branch September 12, 2026 01:50
brettheap pushed a commit that referenced this pull request Oct 23, 2026
…used in each tool's words as one behind a mark is, the compared pair of files is named before it is asserted, and the retyped refusal words are the finders' own (#1176)

RV1188's review of #1188, from the head 024084b:

SHOULD-1 (SonarCloud python:S3415, "Unify assertion argument order in this
file"): the one assert with a bracketed tuple on the left was
`assert (pin.read_bytes(), manifest.read_bytes()) == before`, the shape
#131 (d682127) fixed. The pair is now bound to `now` and compared as
`assert now == before`. Not `after`, which is a function in this file.
Every other `==` assert has the value read on the left; the `in` asserts
keep the text looked for on the left, as `in` reads.

NIT-1: the module docstring, the row's docstring and the PR body said a
space or a tab in front of the key was held "before a mark or after one",
and the rows held no mark and one mark in front of it. A space or a tab in
FRONT of a mark is now a row for each of the three files: refused
unchanged by each tool's own code (update-pin-unrecognised,
update-manifest-no-shape, bump-leg-pin-unrecognised), as the reader refuses
it. Six rows more (126 in all), and the places are named in LEAD_PLACES.

NIT-3: the two end-to-end refusal rows retyped "has 0 `commit` line(s)";
they now use FINDERS["shape-pin-commit"].refused and
FINDERS["leg-pin-commit"].refused, as the in-process rows do.

The tools are untouched.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants