Skip to content

Commit 3f85af0

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

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-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

+91-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,89 @@ 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+
class DefaultSizeNamespaceFixture(t.NamedTuple):
1227+
test_id: str
1228+
TMUXP_DEFAULT_SIZE: t.Optional[str]
1229+
raises: bool
1230+
confoverrides: t.Dict[str, t.Any]
1231+
1232+
1233+
DEFAULT_SIZE_FIXTURES = [
1234+
DefaultSizeNamespaceFixture(
1235+
test_id="v1.13.1 default-size-breaks",
1236+
TMUXP_DEFAULT_SIZE=None,
1237+
raises=True,
1238+
confoverrides={},
1239+
),
1240+
DefaultSizeNamespaceFixture(
1241+
test_id="v1.13.1-option-workaround",
1242+
TMUXP_DEFAULT_SIZE=None,
1243+
raises=False,
1244+
confoverrides={"options": {"default-size": "800x600"}},
1245+
),
1246+
]
1247+
1248+
1249+
@pytest.mark.parametrize(
1250+
DefaultSizeNamespaceFixture._fields,
1251+
DEFAULT_SIZE_FIXTURES,
1252+
ids=[f.test_id for f in DEFAULT_SIZE_FIXTURES],
1253+
)
1254+
@pytest.mark.skipif(has_lt_version("2.9"), reason="default-size only applies there")
1255+
def test_issue_800_default_size_many_windows(
1256+
server: "Server",
1257+
monkeypatch: pytest.MonkeyPatch,
1258+
test_id: str,
1259+
TMUXP_DEFAULT_SIZE: t.Optional[str],
1260+
raises: bool,
1261+
confoverrides: t.Dict[str, t.Any],
1262+
) -> None:
1263+
"""Recreate default-size issue.
1264+
1265+
v1.13.1 added a default-size, but this can break building workspaces with
1266+
a lot of panes.
1267+
1268+
See also: https://github.com/tmux-python/tmuxp/issues/800
1269+
"""
1270+
yaml_config = test_utils.read_config_file(
1271+
"regressions/issue_800_default_size_many_windows.yaml"
1272+
)
1273+
sconfig = kaptan.Kaptan(handler="yaml")
1274+
sconfig = sconfig.import_config(yaml_config).get()
1275+
sconfig = config.expand(sconfig)
1276+
sconfig = config.trickle(sconfig)
1277+
1278+
if isinstance(confoverrides, dict):
1279+
for k, v in confoverrides.items():
1280+
sconfig[k] = v
1281+
1282+
if TMUXP_DEFAULT_SIZE is not None:
1283+
monkeypatch.setenv("TMUXP_DEFAULT_SIZE", TMUXP_DEFAULT_SIZE)
1284+
1285+
builder = WorkspaceBuilder(sconf=sconfig, server=server)
1286+
1287+
if raises:
1288+
with pytest.raises(Exception):
1289+
builder.build()
1290+
1291+
builder.session.kill_session()
1292+
1293+
with pytest.raises(libtmux.exc.LibTmuxException, match="no space for new pane"):
1294+
builder.build()
1295+
return
1296+
1297+
builder.build()
1298+
assert len(server.list_sessions()) == 1
1299+
1300+
# Assign an active pane to the session
1301+
second_session = server.list_sessions()[0]
1302+
first_pane_on_second_session_id = second_session.list_windows()[0].list_panes()[0][
1303+
"pane_id"
1304+
]
1305+
monkeypatch.setenv("TMUX_PANE", first_pane_on_second_session_id)
1306+
1307+
builder = WorkspaceBuilder(sconf=sconfig, server=server)
1308+
1309+
assert builder.find_current_attached_session() == second_session

0 commit comments

Comments
 (0)