Skip to content

Commit 1b8c02a

Browse files
committed
tests(Window.split_window): Add support for size
1 parent 0df4769 commit 1b8c02a

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

tests/test_window.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from libtmux import exc
1010
from libtmux._internal.query_list import ObjectDoesNotExist
11-
from libtmux.common import has_gte_version, has_lt_version
11+
from libtmux.common import has_gte_version, has_lt_version, has_version
1212
from libtmux.constants import ResizeAdjustmentDirection
1313
from libtmux.pane import Pane
1414
from libtmux.server import Server
@@ -171,6 +171,54 @@ def test_split_window_horizontal(session: Session) -> None:
171171
assert float(first_pane.pane_width) <= ((float(window.window_width) + 1) / 2)
172172

173173

174+
def test_split_percentage(session: Session) -> None:
175+
"""Test deprecated percent param."""
176+
window = session.new_window(window_name="split window size")
177+
window.resize(height=100, width=100)
178+
window_height_before = (
179+
int(window.window_height) if isinstance(window.window_height, str) else 0
180+
)
181+
if has_version("3.4"):
182+
pytest.skip(
183+
"tmux 3.4 has a split-window bug."
184+
+ " See https://github.com/tmux/tmux/pull/3840."
185+
)
186+
with pytest.warns(match="Deprecated in favor of size.*"):
187+
pane = window.split_window(percent=10)
188+
assert pane.pane_height == str(int(window_height_before * 0.1))
189+
190+
191+
def test_split_window_size(session: Session) -> None:
192+
"""Window.split_window() respects size."""
193+
window = session.new_window(window_name="split window size")
194+
window.resize(height=100, width=100)
195+
196+
if has_gte_version("3.1"):
197+
pane = window.split_window(size=10)
198+
assert pane.pane_height == "10"
199+
200+
pane = window.split_window(vertical=False, size=10)
201+
assert pane.pane_width == "10"
202+
203+
pane = window.split_window(size="10%")
204+
assert pane.pane_height == "8"
205+
206+
pane = window.split_window(vertical=False, size="10%")
207+
assert pane.pane_width == "8"
208+
else:
209+
window_height_before = (
210+
int(window.window_height) if isinstance(window.window_height, str) else 0
211+
)
212+
window_width_before = (
213+
int(window.window_width) if isinstance(window.window_width, str) else 0
214+
)
215+
pane = window.split_window(size="10%")
216+
assert pane.pane_height == str(int(window_height_before * 0.1))
217+
218+
pane = window.split_window(vertical=False, size="10%")
219+
assert pane.pane_width == str(int(window_width_before * 0.1))
220+
221+
174222
@pytest.mark.parametrize(
175223
"window_name_before,window_name_after",
176224
[("test", "ha ha ha fjewlkjflwef"), ("test", "hello \\ wazzup 0")],

0 commit comments

Comments
 (0)