Skip to content

Commit 75bb6e5

Browse files
committed
tests(Pane): Tests for Pane.resize_pane()
1 parent a2b6831 commit 75bb6e5

File tree

2 files changed

+95
-23
lines changed

2 files changed

+95
-23
lines changed

tests/test_pane.py

Lines changed: 95 additions & 20 deletions
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_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,94 @@ 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+
# Manual: Height percentage
177+
window.select_layout("main-vertical")
178+
pane_height_before = int(pane.pane_height)
179+
pane.resize_pane(
180+
height="15%",
181+
)
182+
assert int(pane.pane_height) == 75
183+
184+
# Manual: Width percentage
185+
window.select_layout("main-horizontal")
186+
pane.resize_pane(
187+
width="15%",
188+
)
189+
assert int(pane.pane_width) == 75
190+
191+
#
192+
# Adjustments
193+
#
194+
195+
# Adjustment: Down
196+
pane_height_before = int(pane.pane_height)
197+
pane.resize_pane(
198+
adjustment_direction=ResizeAdjustmentDirection.Down,
199+
adjustment=pane_height_adjustment * 2,
200+
)
201+
assert pane_height_before - (pane_height_adjustment * 2) == int(pane.pane_height)
202+
203+
# Adjustment: Up
204+
pane_height_before = int(pane.pane_height)
205+
pane.resize_pane(
206+
adjustment_direction=ResizeAdjustmentDirection.Up,
207+
adjustment=pane_height_adjustment,
208+
)
209+
assert pane_height_before + pane_height_adjustment == int(pane.pane_height)
210+
211+
#
212+
# Zoom
213+
#
214+
pane.resize_pane(height=50)
215+
216+
# Zoom
217+
pane.resize_pane(height=2)
218+
pane_height_before = int(pane.pane_height)
219+
pane.resize_pane(
220+
zoom=True,
221+
)
222+
pane_height_expanded = int(pane.pane_height)
223+
assert pane_height_before < pane_height_expanded

tests/test_window.py

Lines changed: 0 additions & 3 deletions
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)