Skip to content

Commit 95bc838

Browse files
committed
tests(Pane,Window): Use direction in .split()
1 parent dbeb554 commit 95bc838

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

tests/legacy_api/test_window.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def test_split_window_horizontal(session: Session) -> None:
159159

160160

161161
@pytest.mark.filterwarnings("ignore:.*deprecated in favor of Window.split()")
162+
@pytest.mark.filterwarnings("ignore:.*vertical is not required to pass with direction.")
162163
def test_split_percentage(
163164
session: Session,
164165
) -> None:
@@ -178,6 +179,37 @@ def test_split_percentage(
178179
assert pane.pane_height == str(int(window_height_before * 0.1))
179180

180181

182+
def test_split_window_size(session: Session) -> None:
183+
"""Window.split_window() respects size."""
184+
window = session.new_window(window_name="split_window window size")
185+
window.resize(height=100, width=100)
186+
187+
if has_gte_version("3.1"):
188+
pane = window.split_window(size=10)
189+
assert pane.pane_height == "10"
190+
191+
pane = window.split_window(vertical=False, size=10)
192+
assert pane.pane_width == "10"
193+
194+
pane = window.split_window(size="10%")
195+
assert pane.pane_height == "8"
196+
197+
pane = window.split_window(vertical=False, size="10%")
198+
assert pane.pane_width == "8"
199+
else:
200+
window_height_before = (
201+
int(window.window_height) if isinstance(window.window_height, str) else 0
202+
)
203+
window_width_before = (
204+
int(window.window_width) if isinstance(window.window_width, str) else 0
205+
)
206+
pane = window.split_window(size="10%")
207+
assert pane.pane_height == str(int(window_height_before * 0.1))
208+
209+
pane = window.split_window(vertical=False, size="10%")
210+
assert pane.pane_width == str(int(window_width_before * 0.1))
211+
212+
181213
@pytest.mark.parametrize(
182214
"window_name_before,window_name_after",
183215
[("test", "ha ha ha fjewlkjflwef"), ("test", "hello \\ wazzup 0")],

tests/test_pane.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
from libtmux.common import has_gte_version, has_lt_version
9-
from libtmux.constants import ResizeAdjustmentDirection
9+
from libtmux.constants import PaneDirection, ResizeAdjustmentDirection
1010
from libtmux.session import Session
1111

1212
logger = logging.getLogger(__name__)
@@ -145,7 +145,7 @@ def test_resize_pane(
145145

146146
window = session.active_window
147147
pane = window.split(attach=False)
148-
window.split(vertical=True, attach=False)
148+
window.split(direction=PaneDirection.Above, attach=False)
149149

150150
assert pane is not None
151151

@@ -236,13 +236,13 @@ def test_split_pane_size(session: Session) -> None:
236236
short_pane = pane.split(size=10)
237237
assert short_pane.pane_height == "10"
238238

239-
narrow_pane = pane.split(vertical=False, size=10)
239+
narrow_pane = pane.split(direction=PaneDirection.Right, size=10)
240240
assert narrow_pane.pane_width == "10"
241241

242242
new_pane = pane.split(size="10%")
243243
assert new_pane.pane_height == "8"
244244

245-
new_pane = short_pane.split(vertical=False, size="10%")
245+
new_pane = short_pane.split(direction=PaneDirection.Right, size="10%")
246246
assert new_pane.pane_width == "10"
247247
else:
248248
window_height_before = (
@@ -254,5 +254,5 @@ def test_split_pane_size(session: Session) -> None:
254254
new_pane = pane.split(size="10%")
255255
assert new_pane.pane_height == str(int(window_height_before * 0.1))
256256

257-
new_pane = new_pane.split(vertical=False, size="10%")
257+
new_pane = new_pane.split(direction=PaneDirection.Right, size="10%")
258258
assert new_pane.pane_width == str(int(window_width_before * 0.1))

tests/test_window.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
from libtmux import exc
1111
from libtmux._internal.query_list import ObjectDoesNotExist
1212
from libtmux.common import has_gte_version, has_lt_version
13-
from libtmux.constants import ResizeAdjustmentDirection, WindowDirection
13+
from libtmux.constants import (
14+
PaneDirection,
15+
ResizeAdjustmentDirection,
16+
WindowDirection,
17+
)
1418
from libtmux.pane import Pane
1519
from libtmux.server import Server
1620
from libtmux.session import Session
@@ -160,7 +164,7 @@ def test_split_horizontal(session: Session) -> None:
160164
"""Window.split() splits window, returns new Pane, horizontal."""
161165
window_name = "test split window"
162166
window = session.new_window(window_name=window_name, attach=True)
163-
pane = window.split(vertical=False)
167+
pane = window.split(direction=PaneDirection.Right)
164168
assert len(window.panes) == 2
165169
assert isinstance(pane, Pane)
166170

@@ -181,13 +185,13 @@ def test_split_size(session: Session) -> None:
181185
pane = window.split(size=10)
182186
assert pane.pane_height == "10"
183187

184-
pane = window.split(vertical=False, size=10)
188+
pane = window.split(direction=PaneDirection.Right, size=10)
185189
assert pane.pane_width == "10"
186190

187191
pane = window.split(size="10%")
188192
assert pane.pane_height == "8"
189193

190-
pane = window.split(vertical=False, size="10%")
194+
pane = window.split(direction=PaneDirection.Right, size="10%")
191195
assert pane.pane_width == "8"
192196
else:
193197
window_height_before = (
@@ -199,7 +203,7 @@ def test_split_size(session: Session) -> None:
199203
pane = window.split(size="10%")
200204
assert pane.pane_height == str(int(window_height_before * 0.1))
201205

202-
pane = window.split(vertical=False, size="10%")
206+
pane = window.split(direction=PaneDirection.Right, size="10%")
203207
assert pane.pane_width == str(int(window_width_before * 0.1))
204208

205209

0 commit comments

Comments
 (0)