[Test Improver] fix(tests): strip ANSI escape codes in test_policy_status._ascii_only#1011
Draft
danielmeppiel wants to merge 1 commit intomainfrom
Draft
[Test Improver] fix(tests): strip ANSI escape codes in test_policy_status._ascii_only#1011danielmeppiel wants to merge 1 commit intomainfrom
danielmeppiel wants to merge 1 commit intomainfrom
Conversation
Rich emits ANSI CSI sequences (\x1b[3m italic, \x1b[1m bold) even when NO_COLOR is unset in the CliRunner environment. The _ascii_only helper was checking raw bytes, causing 7 tests to fail with False negatives. Fix: strip ANSI sequences via regex before the ASCII check, and add _strip_ansi() as a reusable helper in the test module. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Test Improver — automated AI assistant
Problem
test_policy_status.pyhad 7 consistently failing tests. The_ascii_only()helper was returningFalsebecause Rich outputs ANSI CSI escape sequences (\x1b[3mitalic,\x1b[1mbold,\x1b[0mreset) even inside Click'sCliRunner, which does not set a pseudo-TTY. The ESC byte (\x1b, codepoint 0x1B) is categorised asCc(control character) byunicodedata, so the existing guard correctly rejects it — but incorrectly flags Rich's styling codes as a violation.Failures:
Trade-offs
re), one compiled regex, one helper function.\x1b\[[0-9;]*[A-Za-z]covers standard CSI sequences; OSC/DCS sequences are not stripped but don't appear in Rich table output.