mirror of
https://github.com/nextlevelbuilder/ui-ux-pro-max-skill.git
synced 2026-11-28 22:30:32 +00:00
fix(design): keep cip search.py --cip-brief from crashing on a non-UTF-8 stdout (#605)
The brief output has emoji section headers, so printing it to a cp1252 pipe or file (Windows without PYTHONUTF8) raised UnicodeEncodeError. Add the same stdout/stderr guard already used by the other cip scripts, plus a regression test, and mirror both under cli/assets.
This commit is contained in:
parent
a0d04109f4
commit
01706130e3
@ -13,6 +13,14 @@ from pathlib import Path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
from core import search, search_all, get_cip_brief, CSV_CONFIG
|
||||
|
||||
# --cip-brief prints emoji, which raises UnicodeEncodeError when stdout/stderr is
|
||||
# a cp1252 pipe or file (Windows without PYTHONUTF8). Same intent as the guard in
|
||||
# ui-ux-pro-max/scripts/search.py.
|
||||
for _stream in (sys.stdout, sys.stderr):
|
||||
_encoding = getattr(_stream, "encoding", None)
|
||||
if _encoding and _encoding.lower().replace("-", "") != "utf8" and hasattr(_stream, "reconfigure"):
|
||||
_stream.reconfigure(encoding="utf-8", errors=_stream.errors)
|
||||
|
||||
|
||||
def format_results(results, domain):
|
||||
"""Format search results for display"""
|
||||
|
||||
@ -64,3 +64,12 @@ def test_generate_logo_warning_survives_non_utf8_stdout(tmp_path):
|
||||
assert "UnicodeEncodeError" not in result.stderr, result.stderr
|
||||
assert "No logo image provided" in result.stdout
|
||||
assert result.returncode == 1
|
||||
|
||||
|
||||
def test_search_brief_survives_non_utf8_stdout(tmp_path):
|
||||
# search.py --cip-brief prints emoji section headers; it only reads the bundled CSVs.
|
||||
result = _run([CIP / "search.py", "tech startup", "--cip-brief", "--brand", "Cafe"], tmp_path)
|
||||
|
||||
assert "UnicodeEncodeError" not in result.stderr, result.stderr
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert "INDUSTRY" in result.stdout
|
||||
|
||||
@ -13,6 +13,14 @@ from pathlib import Path
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
from core import search, search_all, get_cip_brief, CSV_CONFIG
|
||||
|
||||
# --cip-brief prints emoji, which raises UnicodeEncodeError when stdout/stderr is
|
||||
# a cp1252 pipe or file (Windows without PYTHONUTF8). Same intent as the guard in
|
||||
# ui-ux-pro-max/scripts/search.py.
|
||||
for _stream in (sys.stdout, sys.stderr):
|
||||
_encoding = getattr(_stream, "encoding", None)
|
||||
if _encoding and _encoding.lower().replace("-", "") != "utf8" and hasattr(_stream, "reconfigure"):
|
||||
_stream.reconfigure(encoding="utf-8", errors=_stream.errors)
|
||||
|
||||
|
||||
def format_results(results, domain):
|
||||
"""Format search results for display"""
|
||||
|
||||
@ -64,3 +64,12 @@ def test_generate_logo_warning_survives_non_utf8_stdout(tmp_path):
|
||||
assert "UnicodeEncodeError" not in result.stderr, result.stderr
|
||||
assert "No logo image provided" in result.stdout
|
||||
assert result.returncode == 1
|
||||
|
||||
|
||||
def test_search_brief_survives_non_utf8_stdout(tmp_path):
|
||||
# search.py --cip-brief prints emoji section headers; it only reads the bundled CSVs.
|
||||
result = _run([CIP / "search.py", "tech startup", "--cip-brief", "--brand", "Cafe"], tmp_path)
|
||||
|
||||
assert "UnicodeEncodeError" not in result.stderr, result.stderr
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert "INDUSTRY" in result.stdout
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user