|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
5 | 5 | import logging
|
| 6 | +import pathlib |
6 | 7 | import shutil
|
7 | 8 | import time
|
8 | 9 | import typing as t
|
|
11 | 12 |
|
12 | 13 | from libtmux import exc
|
13 | 14 | from libtmux._internal.query_list import ObjectDoesNotExist
|
| 15 | +from libtmux._internal.types import StrPath |
14 | 16 | from libtmux.common import has_gte_version, has_lt_version, has_lte_version
|
15 | 17 | from libtmux.constants import (
|
16 | 18 | PaneDirection,
|
@@ -653,3 +655,85 @@ def test_window_context_manager(session: Session) -> None:
|
653 | 655 |
|
654 | 656 | # Window should be killed after exiting context
|
655 | 657 | 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