Skip to content

Commit e3423be

Browse files
committed
tests: Add regression for v1.13.1 pane spacing issue
1 parent 2279cb5 commit e3423be

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
session_name: many-windows-issue
2+
windows:
3+
- window_name: moo
4+
layout: main-horizontal
5+
panes:
6+
- echo hello
7+
- echo hello
8+
- echo hello
9+
- echo hello
10+
- echo hello
11+
- echo hello
12+
- echo hello

tests/test_workspacebuilder.py

+60-1
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
import pathlib
44
import textwrap
55
import time
6+
import typing as t
67

78
import pytest
89

910
import kaptan
1011

1112
import libtmux
12-
from libtmux import Window
1313
from libtmux.common import has_gte_version, has_lt_version
1414
from libtmux.test import retry_until, temp_session
15+
from libtmux.window import Window
1516
from tmuxp import config, exc
1617
from tmuxp.cli.load import load_plugins
1718
from tmuxp.workspacebuilder import WorkspaceBuilder
1819

1920
from .constants import EXAMPLE_PATH, FIXTURE_PATH
2021
from .fixtures import utils as test_utils
2122

23+
if t.TYPE_CHECKING:
24+
from libtmux.server import Server
25+
2226

2327
def test_split_windows(session):
2428
yaml_config = test_utils.read_config_file("workspacebuilder/two_pane.yaml")
@@ -1217,3 +1221,58 @@ def is_almost_equal(x, y):
12171221

12181222
assert is_almost_equal(height(panes[0]), height(panes[1]))
12191223
assert is_almost_equal(width(panes[0]), width(panes[1]))
1224+
1225+
1226+
@pytest.mark.skipif(has_lt_version("2.9"), reason="default-size only applies there")
1227+
@pytest.mark.parametrize(
1228+
"TMUXP_DEFAULT_SIZE,raises", [[None, True], ["800x600", False]]
1229+
)
1230+
def test_issue_800_default_size_many_windows(
1231+
server: "Server",
1232+
monkeypatch: pytest.MonkeyPatch,
1233+
TMUXP_DEFAULT_SIZE: t.Optional[str],
1234+
raises: bool,
1235+
) -> None:
1236+
"""Recreate default-size issue.
1237+
1238+
v1.13.1 added a default-size, but this can break building workspaces with
1239+
a lot of panes.
1240+
1241+
See also: https://github.com/tmux-python/tmuxp/issues/800
1242+
"""
1243+
yaml_config = test_utils.read_config_file(
1244+
"regressions/issue_800_default_size_many_windows.yaml"
1245+
)
1246+
sconfig = kaptan.Kaptan(handler="yaml")
1247+
sconfig = sconfig.import_config(yaml_config).get()
1248+
sconfig = config.expand(sconfig)
1249+
sconfig = config.trickle(sconfig)
1250+
1251+
if TMUXP_DEFAULT_SIZE is not None:
1252+
monkeypatch.setenv("TMUXP_DEFAULT_SIZE", TMUXP_DEFAULT_SIZE)
1253+
1254+
builder = WorkspaceBuilder(sconf=sconfig, server=server)
1255+
1256+
if raises:
1257+
with pytest.raises(Exception):
1258+
builder.build()
1259+
1260+
builder.session.kill_session()
1261+
1262+
with pytest.raises(libtmux.exc.LibTmuxException, match="no space for new pane"):
1263+
builder.build()
1264+
return
1265+
1266+
builder.build()
1267+
assert len(server.list_sessions()) == 1
1268+
1269+
# Assign an active pane to the session
1270+
second_session = server.list_sessions()[0]
1271+
first_pane_on_second_session_id = second_session.list_windows()[0].list_panes()[0][
1272+
"pane_id"
1273+
]
1274+
monkeypatch.setenv("TMUX_PANE", first_pane_on_second_session_id)
1275+
1276+
builder = WorkspaceBuilder(sconf=sconfig, server=server)
1277+
1278+
assert builder.find_current_attached_session() == second_session

0 commit comments

Comments
 (0)