8000 types: Add `StrPath` typing, fix `new_session`, part 2 by tony · Pull Request #598 · tmux-python/libtmux · GitHub
[go: up one dir, main page]

Skip to content

types: Add StrPath typing, fix new_session, part 2 #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 26, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
tony committed May 26, 2025
commit a6d220cb8c916e7ebd9b95ff65ada34010a51671
84 changes: 84 additions & 0 deletions tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import logging
import pathlib
import shutil
import time
import typing as t
Expand All @@ -11,6 +12,7 @@

from libtmux import exc
from libtmux._internal.query_list import ObjectDoesNotExist
from libtmux._internal.types import StrPath
from libtmux.common import has_gte_version, has_lt_version, has_lte_version
from libtmux.constants import (
PaneDirection,
Expand Down Expand Up @@ -653,3 +655,85 @@ def test_window_context_manager(session: Session) -> None:

# Window should be killed after exiting context
assert window not in session.windows


class StartDirectoryTestFixture(t.NamedTuple):
"""Test fixture for start_directory parameter testing."""

test_id: str
start_directory: StrPath | None
expected_in_cmd: list[str]
expected_not_in_cmd: list[str]
description: str


START_DIRECTORY_TEST_FIXTURES: list[StartDirectoryTestFixture] = [
StartDirectoryTestFixture(
test_id="none_value",
start_directory=None,
expected_in_cmd=[],
expected_not_in_cmd=["-c"],
description="None should not add -c flag",
),
StartDirectoryTestFixture(
test_id="empty_string",
start_directory="",
expected_in_cmd=[],
expected_not_in_cmd=["-c"],
description="Empty string should not add -c flag",
),
StartDirectoryTestFixture(
test_id="absolute_path_string",
start_directory="/tmp/test",
expected_in_cmd=["-c"],
expected_not_in_cmd=[],
description="Absolute path string should add -c flag",
),
StartDirectoryTestFixture(
test_id="pathlib_absolute",
start_directory=pathlib.Path("/tmp/test"),
expected_in_cmd=["-c"],
expected_not_in_cmd=[],
description="pathlib.Path absolute should add -c flag",
),
]


@pytest.mark.parametrize(
list(StartDirectoryTestFixture._fields),
START_DIRECTORY_TEST_FIXTURES,
ids=[test.test_id for test in START_DIRECTORY_TEST_FIXTURES],
)
def test_split_start_directory(
test_id: str,
start_directory: StrPath | None,
expected_in_cmd: list[str],
expected_not_in_cmd: list[str],
description: str,
session: Session,
) -> None:
"""Test Window.split start_directory parameter handling."""
window = session.new_window(window_name=f"test_window_split_{test_id}")

# Split window with start_directory parameter
new_pane = window.split(start_directory=start_directory)

# Verify pane was created successfully
assert new_pane in window.panes
assert len(wind 5BA8 ow.panes) == 2


def test_split_start_directory_pathlib(session: Session) -> None:
"""Test Window.split accepts pathlib.Path for start_directory."""
import tempfile

with tempfile.TemporaryDirectory() as temp_dir:
path_obj = pathlib.Path(temp_dir)

window = session.new_window(window_name="test_window_split_pathlib")

# Should accept pathlib.Path without error
new_pane = window.split(start_directory=path_obj)

assert new_pane in window.panes
assert len(window.panes) == 2
0