forked from tmux-python/libtmux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pane.py
More file actions
146 lines (118 loc) · 4.64 KB
/
test_pane.py
File metadata and controls
146 lines (118 loc) · 4.64 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""Tests for libtmux Pane object."""
import logging
import shutil
from libtmux.session import Session
logger = logging.getLogger(__name__)
def test_resize_pane(session: Session) -> None:
"""Test Pane.resize_pane()."""
window = session.attached_window
window.rename_window("test_resize_pane")
pane1 = window.attached_pane
assert pane1 is not None
pane1_height = pane1.pane_height
window.split_window()
pane1.resize_pane(height=4)
assert pane1.pane_height != pane1_height
assert pane1.pane_height is not None
assert int(pane1.pane_height) == 4
pane1.resize_pane(height=3)
assert pane1.pane_height is not None
assert int(pane1.pane_height) == 3
def test_send_keys(session: Session) -> None:
"""Verify Pane.send_keys()."""
pane = session.attached_window.attached_pane
assert pane is not None
pane.send_keys("c-c", literal=True)
pane_contents = "\n".join(pane.cmd("capture-pane", "-p").stdout)
assert "c-c" in pane_contents
pane.send_keys("c-a", literal=False)
assert "c-a" not in pane_contents, "should not print to pane"
def test_set_height(session: Session) -> None:
"""Verify Pane.set_height()."""
window = session.new_window(window_name="test_set_height")
window.split_window()
pane1 = window.attached_pane
assert pane1 is not None
pane1_height = pane1.pane_height
pane1.set_height(4)
assert pane1.pane_height != pane1_height
assert pane1.pane_height is not None
assert int(pane1.pane_height) == 4
def test_set_width(session: Session) -> None:
"""Verify Pane.set_width()."""
window = session.new_window(window_name="test_set_width")
window.split_window()
window.select_layout("main-vertical")
pane1 = window.attached_pane
assert pane1 is not None
pane1_width = pane1.pane_width
pane1.set_width(10)
assert pane1.pane_width != pane1_width
assert pane1.pane_width is not None
assert int(pane1.pane_width) == 10
pane1.reset()
def test_capture_pane(session: Session) -> None:
"""Verify Pane.capture_pane()."""
env = shutil.which("env")
assert env is not None, "Cannot find usable `env` in PATH."
session.new_window(
attach=True,
window_name="capture_pane",
window_shell=f"{env} PS1='$ ' sh",
)
pane = session.attached_window.attached_pane
assert pane is not None
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == "$"
pane.send_keys(
r'printf "\n%s\n" "Hello World !"', literal=True, suppress_history=False,
)
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == r'$ printf "\n%s\n" "Hello World !"{}'.format(
"\n\nHello World !\n$",
)
def test_capture_pane_start(session: Session) -> None:
"""Assert Pane.capture_pane() with ``start`` param."""
env = shutil.which("env")
assert env is not None, "Cannot find usable `env` in PATH."
session.new_window(
attach=True,
window_name="capture_pane_start",
window_shell=f"{env} PS1='$ ' sh",
)
pane = session.attached_window.attached_pane
assert pane is not None
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == "$"
pane.send_keys(r'printf "%s"', literal=True, suppress_history=False)
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == '$ printf "%s"\n$'
pane.send_keys("clear -x", literal=True, suppress_history=False)
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == "$"
pane_contents_start = pane.capture_pane(start=-2)
assert pane_contents_start[0] == '$ printf "%s"'
assert pane_contents_start[1] == "$ clear -x"
assert pane_contents_start[-1] == "$"
pane_contents_start = pane.capture_pane(start="-")
assert pane_contents == "$"
def test_capture_pane_end(session: Session) -> None:
"""Assert Pane.capture_pane() with ``end`` param."""
env = shutil.which("env")
assert env is not None, "Cannot find usable `env` in PATH."
session.new_window(
attach=True,
window_name="capture_pane_end",
window_shell=f"{env} PS1='$ ' sh",
)
pane = session.attached_window.attached_pane
assert pane is not None
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == "$"
pane.send_keys(r'printf "%s"', literal=True, suppress_history=False)
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == '$ printf "%s"\n$'
pane_contents = "\n".join(pane.capture_pane(end=0))
assert pane_contents == '$ printf "%s"'
pane_contents = "\n".join(pane.capture_pane(end="-"))
assert pane_contents == '$ printf "%s"\n$'