Skip to content

Commit d491d45

Browse files
committed
tests(test_options[show_options]): Add parametrized tests for show_options()
why: Verify show_options() returns expected keys at all scopes with global and inherited variations. what: - Add ShowOptionsTestCase NamedTuple with test_id pattern - Add expected keys for Server, Session, Window scopes - Add 6 parametrized test cases covering scope/global/inherited combos - Tests verify specific option keys exist in returned dict
1 parent f5b1ae1 commit d491d45

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

tests/test_options.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,3 +1090,111 @@ def test_option_set_show_cycle(server: Server, test_case: OptionTestCase) -> Non
10901090
assert isinstance(result, test_case.expected_type), (
10911091
f"Expected {test_case.expected_type.__name__}, got {type(result).__name__}"
10921092
)
1093+
1094+
1095+
# =============================================================================
1096+
# show_options Tests
1097+
# =============================================================================
1098+
1099+
# Scope-specific expected keys (verified with global_=True)
1100+
SERVER_EXPECTED_KEYS = ["buffer-limit", "escape-time", "exit-empty", "focus-events"]
1101+
SESSION_EXPECTED_KEYS = ["base-index", "history-limit", "status"]
1102+
WINDOW_EXPECTED_KEYS = ["mode-keys", "pane-base-index", "automatic-rename"]
1103+
1104+
1105+
class ShowOptionsTestCase(t.NamedTuple):
1106+
"""Test case for show_options validation."""
1107+
1108+
test_id: str
1109+
scope: OptionScope
1110+
expected_keys: list[str]
1111+
global_: bool = False
1112+
include_inherited: bool = False
1113+
min_version: str = "3.2"
1114+
1115+
1116+
SHOW_OPTIONS_TEST_CASES: list[ShowOptionsTestCase] = [
1117+
# Server scope tests
1118+
ShowOptionsTestCase(
1119+
test_id="server_global",
1120+
scope=OptionScope.Server,
1121+
expected_keys=SERVER_EXPECTED_KEYS,
1122+
global_=True,
1123+
),
1124+
ShowOptionsTestCase(
1125+
test_id="server_global_inherited",
1126+
scope=OptionScope.Server,
1127+
expected_keys=SERVER_EXPECTED_KEYS,
1128+
global_=True,
1129+
include_inherited=True,
1130+
),
1131+
# Session scope tests (require global_=True for defaults)
1132+
ShowOptionsTestCase(
1133+
test_id="session_global",
1134+
scope=OptionScope.Session,
1135+
expected_keys=SESSION_EXPECTED_KEYS,
1136+
global_=True,
1137+
),
1138+
ShowOptionsTestCase(
1139+
test_id="session_global_inherited",
1140+
scope=OptionScope.Session,
1141+
expected_keys=SESSION_EXPECTED_KEYS,
1142+
global_=True,
1143+
include_inherited=True,
1144+
),
1145+
# Window scope tests
1146+
ShowOptionsTestCase(
1147+
test_id="window_global",
1148+
scope=OptionScope.Window,
1149+
expected_keys=WINDOW_EXPECTED_KEYS,
1150+
global_=True,
1151+
),
1152+
ShowOptionsTestCase(
1153+
test_id="window_global_inherited",
1154+
scope=OptionScope.Window,
1155+
expected_keys=WINDOW_EXPECTED_KEYS,
1156+
global_=True,
1157+
include_inherited=True,
1158+
),
1159+
]
1160+
1161+
1162+
def _build_show_options_params() -> list[t.Any]:
1163+
"""Build pytest params for show_options tests."""
1164+
return [pytest.param(tc, id=tc.test_id) for tc in SHOW_OPTIONS_TEST_CASES]
1165+
1166+
1167+
@pytest.mark.parametrize("test_case", _build_show_options_params())
1168+
def test_show_options_returns_expected_keys(
1169+
server: Server,
1170+
test_case: ShowOptionsTestCase,
1171+
) -> None:
1172+
"""Test that show_options() returns dict with expected scope-specific keys."""
1173+
if not has_gte_version(test_case.min_version):
1174+
pytest.skip(f"Requires tmux >= {test_case.min_version}")
1175+
1176+
session = server.new_session(session_name="test_show_options")
1177+
window = session.active_window
1178+
pane = window.active_pane
1179+
assert pane is not None
1180+
1181+
# Use server for all scopes (matches test_options_grid pattern)
1182+
options = server.show_options(
1183+
global_=test_case.global_,
1184+
scope=test_case.scope,
1185+
include_inherited=test_case.include_inherited,
1186+
)
1187+
1188+
assert isinstance(options, dict)
1189+
assert len(options) > 0, (
1190+
f"Expected non-empty dict for scope={test_case.scope.name}, "
1191+
f"global_={test_case.global_}"
1192+
)
1193+
1194+
# Verify expected keys exist (with or without * suffix for inherited)
1195+
for key in test_case.expected_keys:
1196+
# Check for key or key* (inherited marker)
1197+
assert key in options or f"{key}*" in options, (
1198+
f"Expected '{key}' in {test_case.scope.name} options, "
1199+
f"got keys: {list(options.keys())[:10]}..."
1200+
)

0 commit comments

Comments
 (0)