From 83213e86c46fc164539996b7054c329c388c0d19 Mon Sep 17 00:00:00 2001 From: Alpamys Date: Thu, 26 Mar 2026 12:54:38 +0500 Subject: [PATCH] fix: strip ANSI escape codes in CLI help flag tests Rich inserts color codes between flag name parts (e.g. --speculative becomes \x1b[1;36m-\x1b[0m\x1b[1;36m-speculative\x1b[0m), so plain substring match fails in CI. Strip ANSI before asserting. --- tests/test_speculative_decoding.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_speculative_decoding.py b/tests/test_speculative_decoding.py index e8d2986..7126d2a 100644 --- a/tests/test_speculative_decoding.py +++ b/tests/test_speculative_decoding.py @@ -1,10 +1,17 @@ """Tests for speculative decoding — CLI flags, model loading, serve integration.""" +import re from unittest.mock import MagicMock from unittest.mock import patch as mock_patch import pytest + +def _strip_ansi(text: str) -> str: + """Remove ANSI escape codes from Rich-formatted output.""" + return re.sub(r'\x1b\[[0-9;]*m', '', text) + + # ─── CLI Flag Tests ────────────────────────────────────────────────────── @@ -20,7 +27,7 @@ class TestSpeculativeDecodingCLI: runner = CliRunner() result = runner.invoke(app, ["serve", "--help"]) assert result.exit_code == 0 - assert "--speculative-decoding" in result.output + assert "--speculative-decoding" in _strip_ansi(result.output) def test_serve_spec_tokens_flag_exists(self): """The serve command should accept --num-speculative-tokens flag.""" @@ -31,7 +38,7 @@ class TestSpeculativeDecodingCLI: runner = CliRunner() result = runner.invoke(app, ["serve", "--help"]) assert result.exit_code == 0 - assert "--num-speculative-tokens" in result.output + assert "--num-speculative-tokens" in _strip_ansi(result.output) # ─── Draft Model Loading Tests ────────────────────────────────────────────