Skip to content

Commit 12c35b3

Browse files
committed
tests(Pane.split) with start_directory parameter
what: - Introduced StartDirectoryTestFixture for parameter testing - Added tests for various start_directory scenarios including None, empty string, absolute path, and pathlib.Path - Updated test_pane_context_manager to verify pane count after context exit - Added test for pathlib.Path acceptance in Pane.split
1 parent 5305b4a commit 12c35b3

File tree

1 file changed

+93
-4
lines changed

1 file changed

+93
-4
lines changed

tests/test_pane.py

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from __future__ import annotations
44

55
import logging
6+
import pathlib
67
import shutil
78
import typing as t
89

910
import pytest
1011

12+
from libtmux._internal.types import StrPath
1113
from libtmux.common import has_gte_version, has_lt_version, has_lte_version
1214
from libtmux.constants import PaneDirection, ResizeAdjustmentDirection
1315
from libtmux.test.retry import retry_until
@@ -327,11 +329,98 @@ def test_split_pane_size(session: Session) -> None:
327329
def test_pane_context_manager(session: Session) -> None:
328330
"""Test Pane context manager functionality."""
329331
window = session.new_window()
332+
initial_pane_count = len(window.panes)
333+
330334
with window.split() as pane:
331-
pane.send_keys('echo "Hello"')
335+
assert len(window.panes) == initial_pane_count + 1
332336
assert pane in window.panes
333-
assert len(window.panes) == 2 # Initial pane + new pane
334337

335338
# Pane should be killed after exiting context
336-
assert pane not in window.panes
337-
assert len(window.panes) == 1 # Only initial pane remains
339+
window.refresh()
340+
assert len(window.panes) == initial_pane_count
341+
342+
343+
class StartDirectoryTestFixture(t.NamedTuple):
344+
"""Test fixture for start_directory parameter testing."""
345+
346+
test_id: str
347+
start_directory: StrPath | None
348+
expected_in_cmd: list[str]
349+
expected_not_in_cmd: list[str]
350+
description: str
351+
352+
353+
START_DIRECTORY_TEST_FIXTURES: list[StartDirectoryTestFixture] = [
354+
StartDirectoryTestFixture(
355+
test_id="none_value",
356+
start_directory=None,
357+
expected_in_cmd=[],
358+
expected_not_in_cmd=["-c"],
359+
description="None should not add -c flag",
360+
),
361+
StartDirectoryTestFixture(
362+
test_id="empty_string",
363+
start_directory="",
364+
expected_in_cmd=[],
365+
expected_not_in_cmd=["-c"],
366+
description="Empty string should not add -c flag",
367+
),
368+
StartDirectoryTestFixture(
369+
test_id="absolute_path_string",
370+
start_directory="/tmp/test",
371+
expected_in_cmd=["-c"],
372+
expected_not_in_cmd=[],
373+
description="Absolute path string should add -c flag",
374+
),
375+
StartDirectoryTestFixture(
376+
test_id="pathlib_absolute",
377+
start_directory=pathlib.Path("/tmp/test"),
378+
expected_in_cmd=["-c"],
379+
expected_not_in_cmd=[],
380+
description="pathlib.Path absolute should add -c flag",
381+
),
382+
]
383+
384+
385+
@pytest.mark.parametrize(
386+
list(StartDirectoryTestFixture._fields),
387+
START_DIRECTORY_TEST_FIXTURES,
388+
ids=[test.test_id for test in START_DIRECTORY_TEST_FIXTURES],
389+
)
390+
def test_split_start_directory(
391+
test_id: str,
392+
start_directory: StrPath | None,
393+
expected_in_cmd: list[str],
394+
expected_not_in_cmd: list[str],
395+
description: str,
396+
session: Session,
397+
) -> None:
398+
"""Test Pane.split start_directory parameter handling."""
399+
window = session.new_window(window_name=f"test_split_{test_id}")
400+
pane = window.active_pane
401+
assert pane is not None
402+
403+
# Split pane with start_directory parameter
404+
new_pane = pane.split(start_directory=start_directory)
405+
406+
# Verify pane was created successfully
407+
assert new_pane in window.panes
408+
assert len(window.panes) == 2
409+
410+
411+
def test_split_start_directory_pathlib(session: Session) -> None:
412+
"""Test Pane.split accepts pathlib.Path for start_directory."""
413+
import tempfile
414+
415+
with tempfile.TemporaryDirectory() as temp_dir:
416+
path_obj = pathlib.Path(temp_dir)
417+
418+
window = session.new_window(window_name="test_split_pathlib")
419+
pane = window.active_pane
420+
assert pane is not None
421+
422+
# Should accept pathlib.Path without error
423+
new_pane = pane.split(start_directory=path_obj)
424+
425+
assert new_pane in window.panes
426+
assert len(window.panes) == 2

0 commit comments

Comments
 (0)