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

Function test_decode

tests/test_ansi.py:9–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7
8
9def test_decode():
10 console = Console(
11 force_terminal=True, legacy_windows=False, color_system="truecolor"
12 )
13 console.begin_capture()
14 console.print("Hello")
15 console.print("[b]foo[/b]")
16 console.print("[link http://example.org]bar")
17 console.print("[#ff0000 on color(200)]red")
18 console.print("[color(200) on #ff0000]red")
19 terminal_codes = console.end_capture()
20
21 decoder = AnsiDecoder()
22 lines = list(decoder.decode(terminal_codes))
23 print(repr(lines))
24 expected = [
25 Text("Hello"),
26 Text("foo", spans=[Span(0, 3, Style.parse("bold"))]),
27 Text("bar", spans=[Span(0, 3, Style.parse("link http://example.org"))]),
28 Text("red", spans=[Span(0, 3, Style.parse("#ff0000 on color(200)"))]),
29 Text("red", spans=[Span(0, 3, Style.parse("color(200) on #ff0000"))]),
30 Text(""),
31 ]
32
33 assert lines == expected
34
35
36def test_decode_example():

Callers

nothing calls this directly

Calls 10

begin_captureMethod · 0.95
printMethod · 0.95
end_captureMethod · 0.95
decodeMethod · 0.95
ConsoleClass · 0.90
AnsiDecoderClass · 0.90
TextClass · 0.90
SpanClass · 0.90
printFunction · 0.50
parseMethod · 0.45

Tested by

no test coverage detected