Skip to content

Commit b2b6f53

Browse files
authored
tests / fix: Fix v1.13.1 pane spacing issue (#809)
This may negate the fix from #737 (for #667 and #704) that helped certain layouts. If a client hasn't yet been attached, 80x24 isn't enough to handle workspace building splitting the panes out.
2 parents 2b75fb2 + afeb47e commit b2b6f53

File tree

4 files changed

+147
-11
lines changed

4 files changed

+147
-11
lines changed

CHANGES

+28
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,34 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force
2424
- Add [flake8-bugbear](https://github.com/PyCQA/flake8-bugbear) (#807)
2525
- Add [flake8-comprehensions](https://github.com/adamchainz/flake8-comprehensions) (#808)
2626

27+
## tmuxp 1.13.x (2022-09-10)
28+
29+
### Bug fixes
30+
31+
- Layout size has been bumped for those experiencing layout spacing issues
32+
(#809, fixes #800)
33+
34+
If you encounter issues with pane spacing, consider passing an `option` like
35+
so:
36+
37+
```yaml
38+
session_name: main-pane-height
39+
start_directory: "~"
40+
options:
41+
default-size: 999x999
42+
windows:
43+
- window_name: my window name
44+
layout: main-horizontal
45+
options:
46+
main-pane-height: 30
47+
panes:
48+
- shell_command: top
49+
- shell_command: top
50+
- shell_command: top
51+
- shell_command: echo "hey"
52+
- shell_command: echo "moo"
53+
```
54+
2755
## tmuxp 1.13.1 (2022-08-21)
2856
2957
### Bug fixes
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

+95-2
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")
@@ -1209,11 +1213,100 @@ def height(p):
12091213
def width(p):
12101214
return int(p._info["pane_width"])
12111215

1212-
assert height(main_horizontal_pane) > height(panes[0])
1216+
main_horizontal_pane_height = height(main_horizontal_pane)
1217+
pane_heights = [height(pane) for pane in panes]
1218+
# TODO: When libtmux has new pane formatters added, use that to detect top / bottom
1219+
assert all(
1220+
main_horizontal_pane_height != pane_height for pane_height in pane_heights
1221+
), "The top row should not be the same size as the bottom row (even though it can)"
1222+
assert all(
1223+
pane_heights[0] == pane_height for pane_height in pane_heights
1224+
), "The bottom row should be uniform height"
12131225
assert width(main_horizontal_pane) > width(panes[0])
12141226

12151227
def is_almost_equal(x, y):
12161228
return abs(x - y) <= 1
12171229

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

tmuxp/workspacebuilder.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
logger = logging.getLogger(__name__)
2121

22+
DEFAULT_WIDTH = "800"
23+
DEFAULT_HEIGHT = "600"
24+
DEFAULT_SIZE = f"{DEFAULT_WIDTH}x{DEFAULT_HEIGHT}"
25+
2226

2327
class WorkspaceBuilder:
2428

@@ -205,22 +209,21 @@ def build(self, session=None, append=False):
205209
"Session name %s is already running." % self.sconf["session_name"]
206210
)
207211
else:
212+
new_session_kwargs = {}
208213
if "start_directory" in self.sconf:
209-
session = self.server.new_session(
210-
session_name=self.sconf["session_name"],
211-
start_directory=self.sconf["start_directory"],
212-
)
213-
else:
214-
session = self.server.new_session(
215-
session_name=self.sconf["session_name"]
216-
)
214+
new_session_kwargs["start_directory"] = self.sconf[
215+
"start_directory"
216+
]
217+
session = self.server.new_session(
218+
session_name=self.sconf["session_name"]
219+
)
217220

218221
assert self.sconf["session_name"] == session.name
219222
assert len(self.sconf["session_name"]) > 0
220223

221224
if has_gte_version("2.9"):
222225
# Use tmux default session size, overwrite Server::new_session
223-
session.set_option("default-size", "80x24")
226+
session.set_option("default-size", DEFAULT_SIZE)
224227

225228
self.session = session
226229
self.server = session.server

0 commit comments

Comments
 (0)