Skip to content

Commit dab5808

Browse files
committed
tests(test_window): Add deprecation warning tests for Window option methods
why: Verify that deprecated Window methods emit DeprecationWarning correctly what: - Add DeprecatedMethodTestCase NamedTuple for parametrized testing - Add tests for set_window_option, show_window_options, show_window_option - Test both default and global flag variations - Use pytest.warns() to assert deprecation warnings are raised
1 parent 93d9362 commit dab5808

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

tests/test_window.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,75 @@ def test_split_start_directory_pathlib(
797797
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
798798
expected_path = str(user_path.resolve())
799799
assert actual_path == expected_path
800+
801+
802+
# --- Deprecation Warning Tests ---
803+
804+
805+
class DeprecatedMethodTestCase(t.NamedTuple):
806+
"""Test case for deprecated method warnings."""
807+
808+
test_id: str
809+
method_name: str # Name of deprecated method to call
810+
args: tuple[t.Any, ...] # Positional args
811+
kwargs: dict[str, t.Any] # Keyword args
812+
expected_warning_match: str # Regex pattern to match warning message
813+
814+
815+
DEPRECATED_WINDOW_METHOD_TEST_CASES: list[DeprecatedMethodTestCase] = [
816+
DeprecatedMethodTestCase(
817+
test_id="set_window_option",
818+
method_name="set_window_option",
819+
args=("main-pane-height", 20),
820+
kwargs={},
821+
expected_warning_match=r"Window\.set_window_option\(\) is deprecated",
822+
),
823+
DeprecatedMethodTestCase(
824+
test_id="show_window_options",
825+
method_name="show_window_options",
826+
args=(),
827+
kwargs={},
828+
expected_warning_match=r"Window\.show_window_options\(\) is deprecated",
829+
),
830+
DeprecatedMethodTestCase(
831+
test_id="show_window_options_global",
832+
method_name="show_window_options",
833+
args=(),
834+
kwargs={"g": True},
835+
expected_warning_match=r"Window\.show_window_options\(\) is deprecated",
836+
),
837+
DeprecatedMethodTestCase(
838+
test_id="show_window_option",
839+
method_name="show_window_option",
840+
args=("main-pane-height",),
841+
kwargs={},
842+
expected_warning_match=r"Window\.show_window_option\(\) is deprecated",
843+
),
844+
DeprecatedMethodTestCase(
845+
test_id="show_window_option_global",
846+
method_name="show_window_option",
847+
args=("main-pane-height",),
848+
kwargs={"g": True},
849+
expected_warning_match=r"Window\.show_window_option\(\) is deprecated",
850+
),
851+
]
852+
853+
854+
def _build_deprecated_method_params() -> list[t.Any]:
855+
"""Build pytest params for deprecated method tests."""
856+
return [
857+
pytest.param(tc, id=tc.test_id) for tc in DEPRECATED_WINDOW_METHOD_TEST_CASES
858+
]
859+
860+
861+
@pytest.mark.parametrize("test_case", _build_deprecated_method_params())
862+
def test_deprecated_window_methods_emit_warning(
863+
session: Session,
864+
test_case: DeprecatedMethodTestCase,
865+
) -> None:
866+
"""Verify deprecated Window methods emit DeprecationWarning."""
867+
window = session.new_window(window_name="test_deprecation")
868+
method = getattr(window, test_case.method_name)
869+
870+
with pytest.warns(DeprecationWarning, match=test_case.expected_warning_match):
871+
method(*test_case.args, **test_case.kwargs)

0 commit comments

Comments
 (0)