Debian Codegraph @

tests/test_helpers.py

raw symbols SCIP
1 from pytermgui import break_line, real_length, tim
2
3
4 def test_break_plain():
5 text = "123 12345 1234"
6 broken = break_line(text, 3)
7 assert list(broken) == ["123", " 12", "345", " 12", "34"]
8
9
10 def test_break_fancy():
11 text = tim.parse(
12 "[141 bold]Hello there[/ italic ansi-blue] whats up[ansi-cyan bold]?"
13 )
14 broken = break_line(text, 3)
15
16 assert list(broken) == [
17 "\x1b[38;5;141m\x1b[1mHel\x1b[0m",
18 "\x1b[38;5;141m\x1b[1mlo \x1b[0m",
19 "\x1b[38;5;141m\x1b[1mthe\x1b[0m",
20 "\x1b[38;5;141m\x1b[1mre\x1b[0m\x1b[3m\x1b[38;5;4m \x1b[0m",
21 "\x1b[0m\x1b[3m\x1b[38;5;4mwha\x1b[0m",
22 "\x1b[0m\x1b[3m\x1b[38;5;4mts \x1b[0m",
23 "\x1b[0m\x1b[3m\x1b[38;5;4mup\x1b[38;5;6m\x1b[1m?\x1b[0m",
24 ]
25
26
27 def test_break_newline():
28 text = "this is too short\nsike"
29
30 broken = break_line(text, limit=20)
31 assert list(broken) == ["this is too short", "sike"]
32
33
34 # NOTE: This is no longer a part of PTG. It might come back in the future, which is
35 # why the tests are going to stay for now.
36 # def test_get_applied_sequences_full_unset():
37 # text = tim.parse("[249 @green bold]Hello[/ cyan italic]There").rstrip("\x1b[0m")
38 # assert get_applied_sequences(text) == "\x1b[38;5;6m\x1b[3m"
39 #
40 #
41 # def test_get_applied_sequences_fg_unset():
42 # text = tim.parse("[249 @green bold]Hello[/fg italic]There").rstrip("\x1b[0m")
43 # assert get_applied_sequences(text) == "\x1b[48;5;2m\x1b[1m\x1b[3m"
44
45
46 # TODO: There is something wrong with this specific functionality in the pytest env.
47 # It seems like on STANDARD colorsys /bg and /fg sometimes get interpreted as
48 # a normal indexed color, which makes this break. It only happens on STANDARD,
49 # which should hopefully be around 0 users, but we should fix it sometime.
50 # def not_test_get_applied_sequences_bg_unset():
51 # text = "\x1b[38;5;249m\x1b[48;5;2m\x1b[1mHello\x1b[49m\x1b[3mThere"
52 #
53 # assert get_applied_sequences(text) == "\x1b[38;5;249m\x1b[1m\x1b[3m"