From 579b4a263e93160460fbeb3373976a8cae2711ea Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Sat, 8 Aug 2026 16:18:23 -0400 Subject: [PATCH] Guard the rapidfuzz-dependent assertion in test_family_attr_typo_gives_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. --- toolchain/mfc/params_tests/test_validate.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/toolchain/mfc/params_tests/test_validate.py b/toolchain/mfc/params_tests/test_validate.py index f682aced9..71f9f886a 100644 --- a/toolchain/mfc/params_tests/test_validate.py +++ b/toolchain/mfc/params_tests/test_validate.py @@ -85,9 +85,21 @@ def test_family_attr_typo_gives_targeted_error(self): errors = check_unknown_params(params) self.assertEqual(len(errors), 1) self.assertIn("Valid attributes", errors[0]) - self.assertIn("geometry", errors[0]) self.assertNotIn("Did you mean", errors[0]) + @unittest.skipUnless(RAPIDFUZZ_AVAILABLE, "rapidfuzz not installed") + def test_family_attr_typo_lists_intended_attr_first(self): + """The intended attribute must survive truncation of the valid-attribute list. + + _family_attr_error orders by similarity before truncating at 8, so this only + holds when rapidfuzz is installed; without it the list is plain alphabetical + and patch_ib's 26 attributes push 'geometry' past the cut. + """ + params = {"patch_ib(1)%geometri": 1} + errors = check_unknown_params(params) + self.assertEqual(len(errors), 1) + self.assertIn("geometry", errors[0]) + def test_family_valid_attr_no_error(self): """Valid family param should not generate an error.""" params = {"patch_ib(1)%geometry": 1}