Skip to content

Commit 88c0f34

Browse files
committed
tests(Pane): Tests for Pane.resize_pane()
1 parent 6b14e7e commit 88c0f34

File tree

2 files changed

+96
-23
lines changed

2 files changed

+96
-23
lines changed

tests/test_pane.py

+96-20
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,15 @@
22
import logging
33
import shutil
44

5+
import pytest
6+
7+
from libtmux.common import has_gte_version, has_lt_version
8+
from libtmux.constants import ResizeAdjustmentDirection
59
from libtmux.session import Session
610

711
logger = logging.getLogger(__name__)
812

913

10-
def test_resize_pane(session: Session) -> None:
11-
"""Test Pane.resize_pane()."""
12-
window = session.attached_window
13-
window.rename_window("test_resize_pane")
14-
15-
pane1 = window.attached_pane
16-
assert pane1 is not None
17-
pane1_height = pane1.pane_height
18-
window.split_window()
19-
20-
pane1.resize_pane(height=4)
21-
assert pane1.pane_height != pane1_height
22-
assert pane1.pane_height is not None
23-
assert int(pane1.pane_height) == 4
24-
25-
pane1.resize_pane(height=3)
26-
assert pane1.pane_height is not None
27-
assert int(pane1.pane_height) == 3
28-
29-
3014
def test_send_keys(session: Session) -> None:
3115
"""Verify Pane.send_keys()."""
3216
pane = session.attached_window.attached_pane
@@ -146,3 +130,95 @@ def test_capture_pane_end(session: Session) -> None:
146130
assert pane_contents == '$ printf "%s"'
147131
pane_contents = "\n".join(pane.capture_pane(end="-"))
148132
assert pane_contents == '$ printf "%s"\n$'
133+
134+
135+
@pytest.mark.skipif(
136+
has_lt_version("2.9"),
137+
reason="resize-window only exists in tmux 2.9+",
138+
)
139+
def test_resize_pane(
140+
session: Session,
141+
) -> None:
142+
"""Verify resizing window."""
143+
session.cmd("detach-client", "-s")
144+
145+
window = session.attached_window
146+
pane = window.split_window(attach=False)
147+
window.split_window(vertical=True, attach=False)
148+
149+
assert pane is not None
150+
151+
window.resize_window(height=500, width=500)
152+
153+
pane_height_adjustment = 10
154+
155+
assert pane.pane_height is not None
156+
assert pane.pane_width is not None
157+
158+
#
159+
# Manual resizing
160+
#
161+
162+
# Manual: Height
163+
pane_height_before = int(pane.pane_height)
164+
pane.resize_pane(
165+
height="50",
166+
)
167+
assert int(pane.pane_height) == 50
168+
169+
# Manual: Width
170+
window.select_layout("main-horizontal")
171+
pane.resize_pane(
172+
width="75",
173+
)
174+
assert int(pane.pane_width) == 75
175+
176+
if has_gte_version("3.1"):
177+
# Manual: Height percentage
178+
window.select_layout("main-vertical")
179+
pane_height_before = int(pane.pane_height)
180+
pane.resize_pane(
181+
height="15%",
182+
)
183+
assert int(pane.pane_height) == 75
184+
185+
# Manual: Width percentage
186+
window.select_layout("main-horizontal")
187+
pane.resize_pane(
188+
width="15%",
189+
)
190+
assert int(pane.pane_width) == 75
191+
192+
#
193+
# Adjustments
194+
#
195+
196+
# Adjustment: Down
197+
pane_height_before = int(pane.pane_height)
198+
pane.resize_pane(
199+
adjustment_direction=ResizeAdjustmentDirection.Down,
200+
adjustment=pane_height_adjustment * 2,
201+
)
202+
assert pane_height_before - (pane_height_adjustment * 2) == int(pane.pane_height)
203+
204+
# Adjustment: Up
205+
pane_height_before = int(pane.pane_height)
206+
pane.resize_pane(
207+
adjustment_direction=ResizeAdjustmentDirection.Up,
208+
adjustment=pane_height_adjustment,
209+
)
210+
assert pane_height_before + pane_height_adjustment == int(pane.pane_height)
211+
212+
#
213+
# Zoom
214+
#
215+
pane.resize_pane(height=50)
216+
217+
# Zoom
218+
pane.resize_pane(height=2)
219+
pane_height_before = int(pane.pane_height)
220+
pane.resize_pane(
221+
zoom=True,
222+
)
223+
pane_height_expanded = int(pane.pane_height)
224+
assert pane_height_before < pane_height_expanded

tests/test_window.py

-3
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ def test_resize_window(
412412

413413
window = session.attached_window
414414
window_height_adjustment = 10
415-
window_width_adjustment = 10
416415

417416
assert window.window_height is not None
418417
assert window.window_width is not None
@@ -425,14 +424,12 @@ def test_resize_window(
425424
window_height_before = int(window.window_height)
426425
window.resize_window(
427426
height=10,
428-
adjustment=window_height_adjustment,
429427
)
430428
assert int(window.window_height) == 10
431429

432430
# Manual: Width
433431
window.resize_window(
434432
width=10,
435-
adjustment=window_width_adjustment,
436433
)
437434
assert int(window.window_width) == 10
438435

0 commit comments

Comments
 (0)