Skip to content

Commit dc19bff

Browse files
committed
Add ANSI stripping function and update assertions for JSON error messages
1 parent 1ff6134 commit dc19bff

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/test_cli.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typer.testing import CliRunner
55
from unittest import mock
66
from firefly.cli import app, mock_image
7+
import re
78

89
runner = CliRunner()
910

@@ -189,6 +190,10 @@ def test_generate_with_all_new_options(monkeypatch):
189190
assert result.exit_code != 0
190191
assert "content_class must be either 'photo' or 'art'" in result.output
191192

193+
def strip_ansi(text):
194+
ansi_escape = re.compile(r'\x1b\[[0-9;]*[mGKHF]')
195+
return ansi_escape.sub('', text)
196+
192197
def test_generate_invalid_json_style(monkeypatch):
193198
result = runner.invoke(
194199
app,
@@ -202,7 +207,8 @@ def test_generate_invalid_json_style(monkeypatch):
202207
]
203208
)
204209
assert result.exit_code == 2
205-
assert "Invalid JSON for --style" in result.output
210+
assert "Invalid JSON for --style" in strip_ansi(result.output)
211+
206212

207213
def test_generate_invalid_json_structure(monkeypatch):
208214
result = runner.invoke(
@@ -217,7 +223,7 @@ def test_generate_invalid_json_structure(monkeypatch):
217223
]
218224
)
219225
assert result.exit_code == 2
220-
assert "Invalid JSON for --structure" in result.output
226+
assert "Invalid JSON for --structure" in strip_ansi(result.output)
221227

222228
def test_generate_invalid_num_variations(monkeypatch):
223229
# Test too low

0 commit comments

Comments
 (0)