Skip to content

Commit 070700d

Browse files
Fix ANSI color failing unit tests
1 parent 7463926 commit 070700d

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

cycode/cli/apps/scan/scan_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
from pathlib import Path
3-
from typing import Annotated, Any, Optional
3+
from typing import Annotated, Optional
44

55
import click
66
import typer

tests/cli/commands/scan/test_scan_command.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
import click
24
import pytest
35
import typer
@@ -8,6 +10,10 @@
810
from cycode.cli.consts import ISSUE_DETECTED_STATUS_CODE, NO_ISSUES_STATUS_CODE, SCAN_ERROR_STATUS_CODE
911

1012

13+
def _strip_ansi(text: str) -> str:
14+
return re.sub(r'\x1b\[[0-9;]*[mGKHF]', '', text)
15+
16+
1117
def _make_ctx(**obj_overrides: object) -> click.Context:
1218
obj = {
1319
'soft_fail': False,
@@ -31,9 +37,10 @@ class TestScanCommand:
3137
def test_multiple_scan_types_rejected(self) -> None:
3238
result = CliRunner().invoke(app, ['scan', '-t', 'iac', '-t', 'sast', 'path', '.'])
3339
assert result.exit_code == 1
34-
assert '-t/--scan-type' in result.output
35-
assert 'iac' in result.output
36-
assert 'sast' in result.output
40+
output = _strip_ansi(result.output)
41+
assert '-t/--scan-type' in output
42+
assert 'iac' in output
43+
assert 'sast' in output
3744

3845
def test_single_scan_type_accepted(self) -> None:
3946
result = CliRunner().invoke(app, ['scan', '-t', 'iac', '--help'])

0 commit comments

Comments
 (0)