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
Show file tree
Hide file tree
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
tests(start_directory) Improve checks
what:
- Added monkeypatching to change the current working directory to tmp_path in test cases.
- Simplified assertions for current path checks by removing unnecessary conditional statements.
- Ensured consistency in handling expected paths across test files: test_pane.py, test_server.py, test_session.py, and test_window.py.
  • Loading branch information
tony committed May 26, 2025
commit 8483a5b019382b789276c96d86a2896550a9df24
17 changes: 10 additions & 7 deletions tests/test_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,13 @@ def test_split_start_directory(
start_directory: StrPath | None,
description: str,
session: Session,
monkeypatch: pytest.MonkeyPatch,
tmp_path: pathlib.Path,
user_path: pathlib.Path,
) -> None:
"""Test Pane.split start_directory parameter handling."""
monkeypatch.chdir(tmp_path)

window = session.new_window(window_name=f"test_split_{test_id}")
pane = window.active_pane
assert pane is not None
Expand Down Expand Up @@ -415,9 +418,9 @@ def test_split_start_directory(
# Verify working directory if we have an expected path
if expected_path:
new_pane.refresh()
if new_pane.pane_current_path:
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
assert actual_path == expected_path
assert new_pane.pane_current_path is not None
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
assert actual_path == expected_path


def test_split_start_directory_pathlib(
Expand All @@ -436,7 +439,7 @@ def test_split_start_directory_pathlib(

# Verify working directory
new_pane.refresh()
if new_pane.pane_current_path:
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
expected_path = str(user_path.resolve())
assert actual_path == expected_path
assert new_pane.pane_current_path is not None
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
expected_path = str(user_path.resolve())
assert actual_path == expected_path
17 changes: 10 additions & 7 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,13 @@ def test_new_session_start_directory(
start_directory: StrPath | None,
description: str,
server: Server,
monkeypatch: pytest.MonkeyPatch,
tmp_path: pathlib.Path,
user_path: pathlib.Path,
) -> None:
"""Test Server.new_session start_directory parameter handling."""
monkeypatch.chdir(tmp_path)

# Format path placeholders with actual fixture values
actual_start_directory = start_directory
expected_path = None
Expand Down Expand Up @@ -388,9 +391,9 @@ def test_new_session_start_directory(
active_pane = session.active_window.active_pane
assert active_pane is not None
active_pane.refresh()
if active_pane.pane_current_path:
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
assert actual_path == expected_path
assert active_pane.pane_current_path is not None
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
assert actual_path == expected_path


def test_new_session_start_directory_pathlib(
Expand All @@ -410,7 +413,7 @@ def test_new_session_start_directory_pathlib(
active_pane = session.active_window.active_pane
assert active_pane is not None
active_pane.refresh()
if active_pane.pane_current_path:
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
expected_path = str(user_path.resolve())
assert actual_path == expected_path
assert active_pane.pane_current_path is not None
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
expected_path = str(user_path.resolve())
assert actual_path == expected_path
17 changes: 10 additions & 7 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,13 @@ def test_new_window_start_directory(
start_directory: StrPath | None,
description: str,
session: Session,
monkeypatch: pytest.MonkeyPatch,
tmp_path: pathlib.Path,
user_path: pathlib.Path,
) -> None:
"""Test Session.new_window start_directory parameter handling."""
monkeypatch.chdir(tmp_path)

# Format path placeholders with actual fixture values
actual_start_directory = start_directory
expected_path = None
Expand Down Expand Up @@ -511,9 +514,9 @@ def test_new_window_start_directory(
active_pane = window.active_pane
assert active_pane is not None
active_pane.refresh()
if active_pane.pane_current_path:
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
assert actual_path == expected_path
assert active_pane.pane_current_path is not None
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
assert actual_path == expected_path


def test_new_window_start_directory_pathlib(
Expand All @@ -533,7 +536,7 @@ def test_new_window_start_directory_pathlib(
active_pane = window.active_pane
assert active_pane is not None
active_pane.refresh()
if active_pane.pane_current_path:
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
expected_path = str(user_path.resolve())
assert actual_path == expected_path
assert active_pane.pane_current_path is not None
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
expected_path = str(user_path.resolve())
assert actual_path == expected_path
17 changes: 10 additions & 7 deletions tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,13 @@ def test_split_start_directory(
start_directory: StrPath | None,
description: str,
session: Session,
monkeypatch: pytest.MonkeyPatch,
tmp_path: pathlib.Path,
user_path: pathlib.Path,
) -> None:
"""Test Window.split start_directory parameter handling."""
monkeypatch.chdir(tmp_path)

window = session.new_window(window_name=f"test_window_split_{test_id}")

# Format path placeholders with actual fixture values
Expand Down Expand Up @@ -730,9 +733,9 @@ def test_split_start_directory(
# Verify working directory if we have an expected path
if expected_path:
new_pane.refresh()
if new_pane.pane_current_path:
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
assert actual_path == expected_path
assert new_pane.pane_current_path is not None
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
assert actual_path == expected_path


def test_split_start_directory_pathlib(
Expand All @@ -749,7 +752,7 @@ def test_split_start_directory_pathlib(

# Verify working directory
new_pane.refresh()
if new_pane.pane_current_path:
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
expected_path = str(user_path.resolve())
assert actual_path == expected_path
assert new_pane.pane_current_path is not None
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
expected_path = str(user_path.resolve())
assert actual_path == expected_path
0