-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_terminal.py
62 lines (48 loc) · 1.78 KB
/
test_terminal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys
import unittest
from demicode.ui.termio import CSI, OSC, ST, TermIO
class NotATerminal:
"""A class faking just enough of a stream's interface."""
def isatty(self) -> bool:
return True
def fileno(self) -> int:
return sys.__stdout__.fileno()
def write(self, s: str) -> int:
return len(s)
class TestTerminal(unittest.TestCase):
def test_output(self) -> None:
t = TermIO(NotATerminal(), NotATerminal()) # type: ignore
with t.buffer():
t.link("home", "https://apparebit.com")
self.assertEqual(
t.get_buffer(),
"".join([OSC, "8;;https://apparebit.com", ST, "home", OSC, "8;;", ST]),
)
with t.buffer():
t.home().erase_screen()
self.assertEqual(t.get_buffer(), "".join([CSI, ";H", CSI, "2J"]))
with t.buffer():
t.cursor_at_line_start().erase_line()
self.assertEqual(t.get_buffer(), "".join([CSI, "G", CSI, "2K"]))
with t.buffer():
with t.window_title("WINDOW"):
t.write("test")
self.assertEqual(
t.get_buffer(),
"".join([CSI, "22;2t", OSC, "0;WINDOW", ST, "test", CSI, "23;2t"]),
)
with t.buffer():
with t.alternate_screen(), t.hidden_cursor():
t.write("TEST")
self.assertEqual(
t.get_buffer(),
"".join(
[CSI, "?1049h", CSI, "?25l", "TEST", CSI, "?25h", CSI, "?1049l"]
),
)
with t.buffer():
with t.bracketed_paste():
t.write("PASTE")
self.assertEqual(
t.get_buffer(), "".join([CSI, "?2004h", "PASTE", CSI, "?2004l"])
)