Skip to content

Commit

Permalink
!squash tests(test_options): Tests for OptionsMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed May 5, 2024
1 parent 5f2d4b9 commit 5ebd6bb
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/test_options.py
Expand Up @@ -360,6 +360,33 @@ class OptionDataclassTestFixture(t.NamedTuple):
"xterm*": ["clipboard", "ccolour", "cstyle", "focus"],
},
),
OptionDataclassTestFixture(
test_id="command-alias",
option_data=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",
tmux_option="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",
},
),
),
]


Expand All @@ -386,3 +413,42 @@ def test_option_dataclass_fixture(
assert options
assert hasattr(options, dataclass_attribute)
assert getattr(options, dataclass_attribute, None) == expected


@pytest.mark.parametrize(
list(OptionDataclassTestFixture._fields),
TEST_FIXTURES,
ids=[test.test_id for test in TEST_FIXTURES],
)
def test_show_option_pane_fixture(
monkeypatch: pytest.MonkeyPatch,
test_id: str,
option_data: t.List[str],
tmux_option: str,
expected: t.Any,
dataclass_attribute: str,
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)

monkeypatch.setattr(pane, "cmd", fake_cmd(stdout=option_data))

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

0 comments on commit 5ebd6bb

Please sign in to comment.