diff --git a/tests/test_options.py b/tests/test_options.py index ed2a30819..bd8456e25 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -452,3 +452,87 @@ def test_show_option_pane_fixture( assert k in result assert result[k] == v + + +class SetOptionDataclassTestFixture(t.NamedTuple): + """Test fixture raw set_option(s) data into typed libtmux data.""" + + # pytest internal + test_id: str + + # test data + tmux_option: str # e.g. terminal-features + tmux_option_value: t.List[str] # set_option data (raw) + + # results + dataclass_attribute: str # e.g. terminal_features + expected: t.Any # e.g. 50, TerminalFeatures({}), etc. + + +TEST_SET_OPTION_FIXTURES: t.List[SetOptionDataclassTestFixture] = [ + SetOptionDataclassTestFixture( + test_id="command-alias", + tmux_option="command-alias", + tmux_option_value=textwrap.dedent( + """ + command-alias[0] split-pane=split-window + command-alias[1] splitp=split-window + command-alias[2] "server-info=show-messages -JT" + command-alias[3] "info=show-messages -JT" + command-alias[4] "choose-window=choose-tree -w" + command-alias[5] "choose-session=choose-tree -s" + """, + ) + .strip() + .split("\n"), + dataclass_attribute="command_alias", + expected=TmuxArray( + { + "split-pane": "split-window", + "splitp": "split-window", + "server-info": "show-messages -JT", + "info": "show-messages -JT", + "choose-window": "choose-tree -w", + "choose-session": "choose-tree -s", + }, + ), + ), +] + + +@pytest.mark.parametrize( + list(SetOptionDataclassTestFixture._fields), + TEST_SET_OPTION_FIXTURES, + ids=[test.test_id for test in TEST_SET_OPTION_FIXTURES], +) +def test_set_option_pane_fixture( + test_id: str, + tmux_option: str, + tmux_option_value: str, + dataclass_attribute: str, + expected: t.Any, + server: "Server", +) -> None: + """Test Pane.show_option(s)?.""" + session = server.new_session(session_name="test") + window = session.new_window(window_name="test") + pane = window.split_window(attach=False) + + pane.set_option(tmux_option, tmux_option_value) + + result = pane.show_option(tmux_option) + + assert result == expected + + if expected is None: + assert ( + result is not None + ), f"Expected {expected} to be {type(expected)}, got None" + + if isinstance(expected, dict): + assert isinstance(result, dict), f'Expected dict, got "{type(result)}"' + + for k, v in expected.items(): + assert k in result + + assert result[k] == v