Skip to content

Commit 0ccd7cd

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 277bda0 commit 0ccd7cd

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
@@ -722,3 +722,75 @@ def test_split_start_directory_pathlib(
722722
actual_path = str(pathlib.Path(new_pane.pane_current_path).resolve())
723723
expected_path = str(user_path.resolve())
724724
assert actual_path == expected_path
725+
726+
727+
# --- Deprecation Warning Tests ---
728+
729+
730+
class DeprecatedMethodTestCase(t.NamedTuple):
731+
"""Test case for deprecated method warnings."""
732+
733+
test_id: str
734+
method_name: str # Name of deprecated method to call
735+
args: tuple[t.Any, ...] # Positional args
736+
kwargs: dict[str, t.Any] # Keyword args
737+
expected_warning_match: str # Regex pattern to match warning message
738+
739+
740+
DEPRECATED_WINDOW_METHOD_TEST_CASES: list[DeprecatedMethodTestCase] = [
741+
DeprecatedMethodTestCase(
742+
test_id="set_window_option",
743+
method_name="set_window_option",
744+
args=("main-pane-height", 20),
745+
kwargs={},
746+
expected_warning_match=r"Window\.set_window_option\(\) is deprecated",
747+
),
748+
DeprecatedMethodTestCase(
749+
test_id="show_window_options",
750+
method_name="show_window_options",
751+
args=(),
752+
kwargs={},
753+
expected_warning_match=r"Window\.show_window_options\(\) is deprecated",
754+
),
755+
DeprecatedMethodTestCase(
756+
test_id="show_window_options_global",
757+
method_name="show_window_options",
758+
args=(),
759+
kwargs={"g": True},
760+
expected_warning_match=r"Window\.show_window_options\(\) is deprecated",
761+
),
762+
DeprecatedMethodTestCase(
763+
test_id="show_window_option",
764+
method_name="show_window_option",
765+
args=("main-pane-height",),
766+
kwargs={},
767+
expected_warning_match=r"Window\.show_window_option\(\) is deprecated",
768+
),
769+
DeprecatedMethodTestCase(
770+
test_id="show_window_option_global",
771+
method_name="show_window_option",
772+
args=("main-pane-height",),
773+
kwargs={"g": True},
774+
expected_warning_match=r"Window\.show_window_option\(\) is deprecated",
775+
),
776+
]
777+
778+
779+
def _build_deprecated_method_params() -> list[t.Any]:
780+
"""Build pytest params for deprecated method tests."""
781+
return [
782+
pytest.param(tc, id=tc.test_id) for tc in DEPRECATED_WINDOW_METHOD_TEST_CASES
783+
]
784+
785+
786+
@pytest.mark.parametrize("test_case", _build_deprecated_method_params())
787+
def test_deprecated_window_methods_emit_warning(
788+
session: Session,
789+
test_case: DeprecatedMethodTestCase,
790+
) -> None:
791+
"""Verify deprecated Window methods emit DeprecationWarning."""
792+
window = session.new_window(window_name="test_deprecation")
793+
method = getattr(window, test_case.method_name)
794+
795+
with pytest.warns(DeprecationWarning, match=test_case.expected_warning_match):
796+
method(*test_case.args, **test_case.kwargs)

0 commit comments

Comments
 (0)