MCPcopy
hub / github.com/Textualize/rich / test_decode_example

Function test_decode_example

tests/test_ansi.py:36–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34
35
36def test_decode_example():
37 ansi_bytes = b"\x1b[01m\x1b[KC:\\Users\\stefa\\AppData\\Local\\Temp\\tmp3ydingba:\x1b[m\x1b[K In function '\x1b[01m\x1b[Kmain\x1b[m\x1b[K':\n\x1b[01m\x1b[KC:\\Users\\stefa\\AppData\\Local\\Temp\\tmp3ydingba:3:5:\x1b[m\x1b[K \x1b[01;35m\x1b[Kwarning: \x1b[m\x1b[Kunused variable '\x1b[01m\x1b[Ka\x1b[m\x1b[K' [\x1b[01;35m\x1b[K-Wunused-variable\x1b[m\x1b[K]\n 3 | int \x1b[01;35m\x1b[Ka\x1b[m\x1b[K=1;\n | \x1b[01;35m\x1b[K^\x1b[m\x1b[K\n"
38 ansi_text = ansi_bytes.decode("utf-8")
39
40 text = Text.from_ansi(ansi_text)
41
42 console = Console(
43 force_terminal=True, legacy_windows=False, color_system="truecolor"
44 )
45 with console.capture() as capture:
46 console.print(text)
47 result = capture.get()
48 print(repr(result))
49 print(result)
50 expected = "\x1b[1mC:\\Users\\stefa\\AppData\\Local\\Temp\\tmp3ydingba:\x1b[0m In function '\x1b[1mmain\x1b[0m':\n\x1b[1mC:\\Users\\stefa\\AppData\\Local\\Temp\\tmp3ydingba:3:5:\x1b[0m \x1b[1;35mwarning: \x1b[0munused variable '\x1b[1ma\x1b[0m' \n[\x1b[1;35m-Wunused-variable\x1b[0m]\n 3 | int \x1b[1;35ma\x1b[0m=1;\n | \x1b[1;35m^\x1b[0m\n\n"
51 assert result == expected
52
53
54@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 7

captureMethod · 0.95
printMethod · 0.95
ConsoleClass · 0.90
decodeMethod · 0.80
printFunction · 0.50
from_ansiMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected