Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc3b759

Browse files
committed
!squash tmux set options. I want to be able to pass in high-level, "sparse array" objects and for those to set
1 parent dee251c commit bc3b759

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

tests/test_options.py

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ class OptionDataclassTestFixture(t.NamedTuple):
378378
.split("\n"),
379379
dataclass_attribute="command_alias",
380380
tmux_option="command-alias",
381-
expected=TmuxArray(
381+
expected=SparseArray(
382382
{
383383
"split-pane": "split-window",
384384
"splitp": "split-window",
@@ -454,3 +454,87 @@ def test_show_option_pane_fixture(
454454
assert k in result
455455

456456
assert result[k] == v
457+
458+
459+
class SetOptionDataclassTestFixture(t.NamedTuple):
460+
"""Test fixture raw set_option(s) data into typed libtmux data."""
461+
462+
# pytest internal
463+
test_id: str
464+
465+
# test data
466+
tmux_option: str # e.g. terminal-features
467+
tmux_option_value: list[str] # set_option data (raw)
468+
469+
# results
470+
dataclass_attribute: str # e.g. terminal_features
471+
expected: t.Any # e.g. 50, TerminalFeatures({}), etc.
472+
473+
474+
TEST_SET_OPTION_FIXTURES: list[SetOptionDataclassTestFixture] = [
475+
SetOptionDataclassTestFixture(
476+
test_id="command-alias",
477+
tmux_option="command-alias",
478+
tmux_option_value=textwrap.dedent(
479+
"""
480+
command-alias[0] split-pane=split-window
481+
command-alias[1] splitp=split-window
482+
command-alias[2] "server-info=show-messages -JT"
483+
command-alias[3] "info=show-messages -JT"
484+
command-alias[4] "choose-window=choose-tree -w"
485+
command-alias[5] "choose-session=choose-tree -s"
486+
""",
487+
)
488+
.strip()
489+
.split("\n"),
490+
dataclass_attribute="command_alias",
491+
expected=SparseArray(
492+
{
493+
"split-pane": "split-window",
494+
"splitp": "split-window",
495+
"server-info": "show-messages -JT",
496+
"info": "show-messages -JT",
497+
"choose-window": "choose-tree -w",
498+
"choose-session": "choose-tree -s",
499+
},
500+
),
501+
),
502+
]
503+
504+
505+
@pytest.mark.parametrize(
506+
list(SetOptionDataclassTestFixture._fields),
507+
TEST_SET_OPTION_FIXTURES,
508+
ids=[test.test_id for test in TEST_SET_OPTION_FIXTURES],
509+
)
510+
def test_set_option_pane_fixture(
511+
test_id: str,
512+
tmux_option: str,
513+
tmux_option_value: str,
514+
dataclass_attribute: str,
515+
expected: t.Any,
516+
server: Server,
517+
) -> None:
518+
"""Test Pane.show_option(s)?."""
519+
session = server.new_session(session_name="test")
520+
window = session.new_window(window_name="test")
521+
pane = window.split_window(attach=False)
522+
523+
pane.set_option(tmux_option, tmux_option_value)
524+
525+
result = pane.show_option(tmux_option)
526+
527+
assert result == expected
528+
529+
if expected is None:
530+
assert result is not None, (
531+
f"Expected {expected} to be {type(expected)}, got None"
532+
)
533+
534+
if isinstance(expected, dict):
535+
assert isinstance(result, dict), f'Expected dict, got "{type(result)}"'
536+
537+
for k, v in expected.items():
538+
assert k in result
539+
540+
assert result[k] == v

0 commit comments

Comments
 (0)