|
2 | 2 | import logging
|
3 | 3 | import shutil
|
4 | 4 |
|
| 5 | +import pytest |
| 6 | + |
| 7 | +from libtmux.common import has_gte_version, has_lt_version |
| 8 | +from libtmux.constants import ResizeAdjustmentDirection |
5 | 9 | from libtmux.session import Session
|
6 | 10 |
|
7 | 11 | logger = logging.getLogger(__name__)
|
8 | 12 |
|
9 | 13 |
|
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 |
| - |
30 | 14 | def test_send_keys(session: Session) -> None:
|
31 | 15 | """Verify Pane.send_keys()."""
|
32 | 16 | pane = session.attached_window.attached_pane
|
@@ -146,3 +130,95 @@ def test_capture_pane_end(session: Session) -> None:
|
146 | 130 | assert pane_contents == '$ printf "%s"'
|
147 | 131 | pane_contents = "\n".join(pane.capture_pane(end="-"))
|
148 | 132 | 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 |
0 commit comments