Skip to content

Commit 8483a5b

Browse files
committed
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.
1 parent 905e395 commit 8483a5b

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

tests/test_pane.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,13 @@ def test_split_start_directory(
382382
start_directory: StrPath | None,
383383
description: str,
384384
session: Session,
385+
monkeypatch: pytest.MonkeyPatch,
385386
tmp_path: pathlib.Path,
386387
user_path: pathlib.Path,
387388
) -> None:
388389
"""Test Pane.split start_directory parameter handling."""
390+
monkeypatch.chdir(tmp_path)
391+
389392
window = session.new_window(window_name=f"test_split_{test_id}")
390393
pane = window.active_pane
391394
assert pane is not None
@@ -415,9 +418,9 @@ def test_split_start_directory(
415418
# Verify working directory if we have an expected path
416419
if expected_path:
417420
new_pane.refresh()
418-
if new_pane.pane_current_path:
419-
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
420-
assert actual_path == expected_path
421+
assert new_pane.pane_current_path is not None
422+
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
423+
assert actual_path == expected_path
421424

422425

423426
def test_split_start_directory_pathlib(
@@ -436,7 +439,7 @@ def test_split_start_directory_pathlib(
436439

437440
# Verify working directory
438441
new_pane.refresh()
439-
if new_pane.pane_current_path:
440-
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
441-
expected_path = str(user_path.resolve())
442-
assert actual_path == expected_path
442+
assert new_pane.pane_current_path is not None
443+
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
444+
expected_path = str(user_path.resolve())
445+
assert actual_path == expected_path

tests/test_server.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,13 @@ def test_new_session_start_directory(
354354
start_directory: StrPath | None,
355355
description: str,
356356
server: Server,
357+
monkeypatch: pytest.MonkeyPatch,
357358
tmp_path: pathlib.Path,
358359
user_path: pathlib.Path,
359360
) -> None:
360361
"""Test Server.new_session start_directory parameter handling."""
362+
monkeypatch.chdir(tmp_path)
363+
361364
# Format path placeholders with actual fixture values
362365
actual_start_directory = start_directory
363366
expected_path = None
@@ -388,9 +391,9 @@ def test_new_session_start_directory(
388391
active_pane = session.active_window.active_pane
389392
assert active_pane is not None
390393
active_pane.refresh()
391-
if active_pane.pane_current_path:
392-
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
393-
assert actual_path == expected_path
394+
assert active_pane.pane_current_path is not None
395+
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
396+
assert actual_path == expected_path
394397

395398

396399
def test_new_session_start_directory_pathlib(
@@ -410,7 +413,7 @@ def test_new_session_start_directory_pathlib(
410413
active_pane = session.active_window.active_pane
411414
assert active_pane is not None
412415
active_pane.refresh()
413-
if active_pane.pane_current_path:
414-
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
415-
expected_path = str(user_path.resolve())
416-
assert actual_path == expected_path
416+
assert active_pane.pane_current_path is not None
417+
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
418+
expected_path = str(user_path.resolve())
419+
assert actual_path == expected_path

tests/test_session.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,13 @@ def test_new_window_start_directory(
477477
start_directory: StrPath | None,
478478
description: str,
479479
session: Session,
480+
monkeypatch: pytest.MonkeyPatch,
480481
tmp_path: pathlib.Path,
481482
user_path: pathlib.Path,
482483
) -> None:
483484
"""Test Session.new_window start_directory parameter handling."""
485+
monkeypatch.chdir(tmp_path)
486+
484487
# Format path placeholders with actual fixture values
485488
actual_start_directory = start_directory
486489
expected_path = None
@@ -511,9 +514,9 @@ def test_new_window_start_directory(
511514
active_pane = window.active_pane
512515
assert active_pane is not None
513516
active_pane.refresh()
514-
if active_pane.pane_current_path:
515-
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
516-
assert actual_path == expected_path
517+
assert active_pane.pane_current_path is not None
518+
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
519+
assert actual_path == expected_path
517520

518521

519522
def test_new_window_start_directory_pathlib(
@@ -533,7 +536,7 @@ def test_new_window_start_directory_pathlib(
533536
active_pane = window.active_pane
534537
assert active_pane is not None
535538
active_pane.refresh()
536-
if active_pane.pane_current_path:
537-
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
538-
expected_path = str(user_path.resolve())
539-
assert actual_path == expected_path
539+
assert active_pane.pane_current_path is not None
540+
actual_path = str(pathlib.Path(active_pane.pane_current_path).resolve())
541+
expected_path = str(user_path.resolve())
542+
assert actual_path == expected_path

tests/test_window.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,13 @@ def test_split_start_directory(
699699
start_directory: StrPath | None,
700700
description: str,
701701
session: Session,
702+
monkeypatch: pytest.MonkeyPatch,
702703
tmp_path: pathlib.Path,
703704
user_path: pathlib.Path,
704705
) -> None:
705706
"""Test Window.split start_directory parameter handling."""
707+
monkeypatch.chdir(tmp_path)
708+
706709
window = session.new_window(window_name=f"test_window_split_{test_id}")
707710

708711
# Format path placeholders with actual fixture values
@@ -730,9 +733,9 @@ def test_split_start_directory(
730733
# Verify working directory if we have an expected path
731734
if expected_path:
732735
new_pane.refresh()
733-
if new_pane.pane_current_path:
734-
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
735-
assert actual_path == expected_path
736+
assert new_pane.pane_current_path is not None
737+
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
738+
assert actual_path == expected_path
736739

737740

738741
def test_split_start_directory_pathlib(
@@ -749,7 +752,7 @@ def test_split_start_directory_pathlib(
749752

750753
# Verify working directory
751754
new_pane.refresh()
752-
if new_pane.pane_current_path:
753-
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
754-
expected_path = str(user_path.resolve())
755-
assert actual_path == expected_path
755+
assert new_pane.pane_current_path is not None
756+
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
757+
expected_path = str(user_path.resolve())
758+
assert actual_path == expected_path

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy