Skip to content

Guard the rapidfuzz-dependent assertion in test_validate - #1705

Open
sbryngelson wants to merge 1 commit into
masterfrom
fix/test-validate-rapidfuzz-guard
Open

Guard the rapidfuzz-dependent assertion in test_validate#1705
sbryngelson wants to merge 1 commit into
masterfrom
fix/test-validate-rapidfuzz-guard

Conversation

@sbryngelson

@sbryngelson sbryngelson commented Aug 8, 2026

Copy link
Copy Markdown
Member

test_family_attr_typo_gives_targeted_error fails rather than skips when rapidfuzz is not importable.

Cause

The test feeds patch_ib(1)%geometri to check_unknown_params and asserts that geometry appears in the resulting "Valid attributes: ..." list. _family_attr_error (toolchain/mfc/params/validate.py:78-90) orders candidates by similarity and then truncates at 8 entries:

similar = suggest_similar(attr, valid, max_suggestions=len(valid))
ordered = similar + [v for v in valid if v not in similar] if similar else valid
if len(ordered) > 8:
    shown = ", ".join(ordered[:8]) + f", ... ({len(ordered)} total)"

suggest.py degrades gracefully when the import fails — RAPIDFUZZ_AVAILABLE = False and suggest_similar returns [] — so the ordering falls back to plain alphabetical. patch_ib now has 26 attributes and geometry sits past the 8-entry cut behind airfoil_id, angles(1..3), angular_vel(1..3), burn_rate_exp, so the assertion fails.

rapidfuzz is a declared dependency in toolchain/pyproject.toml, so a properly provisioned environment always has it and CI is unaffected. But suggest.py supports running without it, and the two neighbouring tests in the same class that depend on fuzzy matching already carry @unittest.skipUnless(RAPIDFUZZ_AVAILABLE, "rapidfuzz not installed"). This one was missed, so a partial environment gets a failure instead of a skip.

Change

Split the similarity-ordering assertion into its own guarded test. The rapidfuzz-independent assertions — one error, "Valid attributes" present, no "Did you mean" — stay unguarded so the targeted-error path keeps its coverage either way.

Verification

without rapidfuzz:  22 passed, 3 skipped
with rapidfuzz:     25 passed
ruff check / ruff format --check:  clean

…s_targeted_error

test_family_attr_typo_gives_targeted_error asserted that 'geometry' appears in
the valid-attribute list for a patch_ib(1)%geometri typo. That only holds when
rapidfuzz is installed: _family_attr_error orders candidates by similarity
before truncating the list at 8 entries, and without rapidfuzz suggest_similar
returns an empty list, so the ordering falls back to alphabetical and
patch_ib's 26 attributes push 'geometry' past the cut.

The test therefore failed rather than skipped in environments without the
optional dependency, unlike the two neighbouring tests in the same class that
already carry @unittest.skipUnless(RAPIDFUZZ_AVAILABLE, ...).

Split the similarity-ordering assertion into its own guarded test and leave the
rapidfuzz-independent assertions (targeted error, no 'Did you mean') running
unconditionally, so coverage of the base path is not lost.
Copilot AI lite review requested due to automatic review settings August 8, 2026 20:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a unit-test robustness issue in the Python parameter-validation test suite by ensuring an assertion that depends on the optional rapidfuzz dependency is only evaluated when rapidfuzz is available, while keeping the rapidfuzz-independent coverage in place.

Changes:

  • Removes the unguarded assertion that "geometry" appears in the truncated “Valid attributes …” list for a family-attribute typo.
  • Adds a new @unittest.skipUnless(RAPIDFUZZ_AVAILABLE, ...) test that asserts "geometry" is present when similarity ordering (via rapidfuzz) is available.

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

Comment on lines +91 to +93
def test_family_attr_typo_lists_intended_attr_first(self):
"""The intended attribute must survive truncation of the valid-attribute list.

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.77%. Comparing base (8dfe8c7) to head (579b4a2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1705   +/-   ##
=======================================
  Coverage   60.77%   60.77%           
=======================================
  Files          83       83           
  Lines       20872    20872           
  Branches     3101     3101           
=======================================
  Hits        12685    12685           
  Misses       6121     6121           
  Partials     2066     2066           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants