Skip to content

Commit a6d220c

Browse files
committed
tests(window[split]) Add start_directory tests
what: - Added tests for start_directory parameter handling in Window.split - Included scenarios for None, empty string, absolute path, and pathlib.Path - Verified correct pane creation and command generation based on start_directory values - Ensured compatibility with pathlib.Path for start_directory input
1 parent 9202412 commit a6d220c

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

tests/test_window.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import logging
6+
import pathlib
67
import shutil
78
import time
89
import typing as t
@@ -11,6 +12,7 @@
1112

1213
from libtmux import exc
1314
from libtmux._internal.query_list import ObjectDoesNotExist
15+
from libtmux._internal.types import StrPath
1416
from libtmux.common import has_gte_version, has_lt_version, has_lte_version
1517
from libtmux.constants import (
1618
PaneDirection,
@@ -653,3 +655,85 @@ def test_window_context_manager(session: Session) -> None:
653655

654656
# Window should be killed after exiting context
655657
assert window not in session.windows
658+
659+
660+
class StartDirectoryTestFixture(t.NamedTuple):
661+
"""Test fixture for start_directory parameter testing."""
662+
663+
test_id: str
664+
start_directory: StrPath | None
665+
expected_in_cmd: list[str]
666+
expected_not_in_cmd: list[str]
667+
description: str
668+
669+
670+
START_DIRECTORY_TEST_FIXTURES: list[StartDirectoryTestFixture] = [
671+
StartDirectoryTestFixture(
672+
test_id="none_value",
673+
start_directory=None,
674+
expected_in_cmd=[],
675+
expected_not_in_cmd=["-c"],
676+
description="None should not add -c flag",
677+
),
678+
StartDirectoryTestFixture(
679+
test_id="empty_string",
680+
start_directory="",
681+
expected_in_cmd=[],
682+
expected_not_in_cmd=["-c"],
683+
description="Empty string should not add -c flag",
684+
),
685+
StartDirectoryTestFixture(
686+
test_id="absolute_path_string",
687+
start_directory="/tmp/test",
688+
expected_in_cmd=["-c"],
689+
expected_not_in_cmd=[],
690+
description="Absolute path string should add -c flag",
691+
),
692+
StartDirectoryTestFixture(
693+
test_id="pathlib_absolute",
694+
start_directory=pathlib.Path("/tmp/test"),
695+
expected_in_cmd=["-c"],
696+
expected_not_in_cmd=[],
697+
description="pathlib.Path absolute should add -c flag",
698+
),
699+
]
700+
701+
702+
@pytest.mark.parametrize(
703+
list(StartDirectoryTestFixture._fields),
704+
START_DIRECTORY_TEST_FIXTURES,
705+
ids=[test.test_id for test in START_DIRECTORY_TEST_FIXTURES],
706+
)
707+
def test_split_start_directory(
708+
test_id: str,
709+
start_directory: StrPath | None,
710+
expected_in_cmd: list[str],
711+
expected_not_in_cmd: list[str],
712+
description: str,
713+
session: Session,
714+
) -> None:
715+
"""Test Window.split start_directory parameter handling."""
716+
window = session.new_window(window_name=f"test_window_split_{test_id}")
717+
718+
# Split window with start_directory parameter
719+
new_pane = window.split(start_directory=start_directory)
720+
721+
# Verify pane was created successfully
722+
assert new_pane in window.panes
723+
assert len(window.panes) == 2
724+
725+
726+
def test_split_start_directory_pathlib(session: Session) -> None:
727+
"""Test Window.split accepts pathlib.Path for start_directory."""
728+
import tempfile
729+
730+
with tempfile.TemporaryDirectory() as temp_dir:
731+
path_obj = pathlib.Path(temp_dir)
732+
733+
window = session.new_window(window_name="test_window_split_pathlib")
734+
735+
# Should accept pathlib.Path without error
736+
new_pane = window.split(start_directory=path_obj)
737+
738+
assert new_pane in window.panes
739+
assert len(window.panes) == 2

0 commit comments

Comments
 (0)