main
py 45 lines 1.04 KB
Raw
1 import sys
2 from pathlib import Path
3
4 import pytest
5
6 PROJECT_ROOT = Path(__file__).resolve().parents[1]
7 if str(PROJECT_ROOT) not in sys.path:
8 sys.path.insert(0, str(PROJECT_ROOT))
9
10 from helpers.print_style import PrintStyle
11
12
13 class _PassthroughSecretsManager:
14 def mask_values(self, text: str) -> str:
15 return text
16
17
18 @pytest.fixture(autouse=True)
19 def _reset_print_style_state():
20 PrintStyle.last_endline = True
21 yield
22 PrintStyle.last_endline = True
23
24
25 def test_get_sanitizes_lone_surrogates():
26 style = PrintStyle(log_only=True)
27 style.secrets_mgr = _PassthroughSecretsManager()
28
29 plain_text, styled_text, html_text = style.get("bad \ud83d")
30
31 assert plain_text == "bad ?"
32 assert "\ud83d" not in styled_text
33 assert "\ud83d" not in html_text
34
35
36 def test_print_sanitizes_lone_surrogates_without_crash(capsys):
37 style = PrintStyle()
38 style.secrets_mgr = _PassthroughSecretsManager()
39
40 style.print("bad \ud83d")
41
42 content = capsys.readouterr().out
43
44 assert "bad ?" in content
45 assert "\ud83d" not in content