10000 Improved option management, add hook management by tony · Pull Request #516 · tmux-python/libtmux · GitHub
[go: up one dir, main page]

Skip to content

Improved option management, add hook management #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
2d40e6c
docs(test-helpers) Update to existing modules
tony Feb 27, 2025
e8b5d7a
docs(test-helpers) Add retry page
tony Feb 27, 2025
76326f3
py(deps[dev]) Bump dev packages
tony Feb 27, 2025 10000
1668b45
chore: Add `__init__.py` for tests/examples
tony Feb 27, 2025
fc3dec2
chore: Add `__init__.py` for tests/examples/test
tony Feb 26, 2025
a438f2d
chore: Add `__init__.py` for tests/examples/_internal/waiter
tony Feb 27, 2025
aa260f2
fix(retry): Improve retry_until_extended function with better error m…
tony Feb 26, 2025
10a37e5
feat(waiter): Enhance terminal content waiting utility with fluent AP…
tony Feb 26, 2025
0c74d33
test(waiter): Fix test cases and improve type safety
tony Feb 26, 2025
a10493a
docs(waiter): Add comprehensive documentation for terminal content wa…
tony Feb 26, 2025
6bdbb5c
pyproject(mypy[exceptions]): examples to ignore `no-untyped-def`
tony Feb 26, 2025
d436d75
test: add conftest.py to register example marker
tony Feb 26, 2025
17d2967
refactor(tests[waiter]): Add waiter test examples into individual files
tony Feb 26, 2025
50081b5
docs(CHANGES) Note `Waiter`
tony Feb 27, 2025
db47652
feat(waiter): Add terminal content waiting utility for testing (#582)
tony Feb 27, 2025
9661039
cursor(rules[git-commits]) Use component name first
tony Feb 28, 2025
677aa96
cursor(rules[git-commits]) Standardize further
tony Feb 28, 2025
60d1386
cursor(rules[dev-loop]) Use `--show-fixes` in `ruff check`
tony Feb 28, 2025
b5b4a8c
feat!(Window): Set option flags
tony Feb 5, 2024
84bfbc1
refactor!(Window): Deprecate set_window_option -> set_option
tony Feb 5, 2024
5cf3321
tests(Window): Rename test for show_window_options()
tony Feb 6, 2024
4a314ce
tests(Window): set_option
tony Feb 6, 2024
1e00ae6
Window: Add show_option(), deprecate show_window_option()
tony Feb 6, 2024
4596b56
chore(Window): {set,show}-window-option -> {set,show}-option -w
tony Feb 6, 2024
486cdce
libtmux.constants: Add OptionScope and OPTION_SCOPE_FLAG_MAP
tony Feb 6, 2024
7e9a6e6
feat(Window): scope param for Window.{set,show}_option
tony Feb 6, 2024
ae6da1c
tests(Window): show_options w/ scope
tony Feb 6, 2024
c5aa606
tests: show_window_option() -> show_option()
tony Feb 6, 2024
16a1396
feat(common): Add CmdMixin, CmdProtocol
tony Feb 8, 2024
7c11e71
refactor!(options): Move handle_options_error -> options
tony Feb 8, 2024
40b529c
feat(internal[sparse_array]): Add SparseArray
tony Jun 20, 2024
df0656f
feat(options): Add OptionsMixin
tony Feb 8, 2024
77ca697
feat(Window): Use OptionsMixin for Window.set_option, Window.show_opt…
tony Feb 7, 2024
7cd87f2
feat(Pane): Use OptionsMixin for Pane.set_option, Pane.show_option(s)
tony Feb 5, 2024
c34a6b4
feat(Session): Use OptionsMixin for Session.set_option, Session.show_…
tony Feb 7, 2024
f2bc27a
feat(Server): Use OptionsMixin for Server.set_option, Server.show_opt…
tony Feb 8, 2024
9b9c399
tests: Handle Window.show_options scope mismatch
tony Feb 7, 2024
3fd8319
tests(window): Version guard to scope
tony Feb 6, 2024
9696b16
tests(Window): For Window.default_option_scope
tony Feb 8, 2024
3360993
docs(options): Add page for option helpers
tony Feb 8, 2024
f92a835
internal(constants[options]): GPT generated dataclasses
tony Feb 9, 2024
2d9e2b7
tests(test_options): Test OptionsMixin
tony Feb 8, 2024
f96093b
docs(CHANGES): Note updates for options
tony Feb 6, 2024
1756f9c
constants: Add HOOK_SCOPE_FLAG_MAP
tony Feb 16, 2024
e62484d
docs(API): Document internal constants
tony Feb 15, 2024
ce8fbac
feat(internal[constants]): Add Hooks data structure
tony Feb 15, 2024
a03f1cc
feat!(hooks): HooksMixin
tony Feb 15, 2024
39b5caa
feat(Pane): Add HooksMixin
tony Feb 15, 2024
0ccc4f4
feat(Window): Add HooksMixin
tony Feb 15, 2024
873f29d
feat(Session): Add HooksMixin
tony Feb 15, 2024
9773e84
feat(Server): Add HooksMixin
tony Feb 15, 2024
5f80216
docs(API): Add Hooks
tony Feb 16, 2024
68a09bd
tests(test_hooks): Test HooksMixin
tony Feb 15, 2024
7c92836
!squash tests(test_options): Tests for OptionsMixin
tony Apr 13, 2024
dee251c
!squash test_options: renamings
tony May 5, 2024
bc3b759
!squash tmux set options. I want to be able to pass in high-level, "…
tony May 5, 2024
e855ff7
Revert "!squash tmux set options. I want to be able to pass in high-…
tony Jun 20, 2024
efe6884
!squash test_options: Stable baseline
tony Jun 20, 2024
fa47cdb
!squash to feat(Window): scope param for Window.{set,show}_option
tony Jul 20, 2024
66abda8
fix(options): improve type safety for SparseArray handling
tony Feb 23, 2025
73dd13c
test(options): update terminal-features test for tmux 3.4
tony Feb 23, 2025
57383bf
test(options): improve test coverage and type safety
tony Feb 23, 2025
1616798
fix(tests): improve type safety in style option tests
tony Feb 23, 2025
d78af39
fix(tests): handle status-format version compatibility
tony Feb 23, 2025
7bff126
fix(tests): handle update-environment version compatibility
tony Feb 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
!squash test_options: Stable baseline
  • Loading branch information
tony committed Feb 28, 2025
commit efe6884b41df73c9efaae711fa51aa5d1b6995ee
53 changes: 53 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,56 @@ def test_show_option_pane_fixture(
assert k in result

assert result[k] == v


def test_stable_baseline_options_and_hooks(server: Server) -> None:
"""Ensure stable baseline across tmux versions."""
session = server.new_session(session_name="test", detach=True)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider adding tests for hooks with different scopes

The test suite should include test cases that verify hook behavior with different scopes (server, session, window, pane) to ensure that hooks are working as expected in all contexts.

Suggested implementation:

def test_stable_baseline_options_and_hooks(server: Server) -> None:
    """Ensure stable baseline across tmux versions."""
    session = server.new_session(session_name="test", detach=True)
    window = session.attached_window
    pane = window.attached_pane

    # Test server-level hooks
    server.set_hook("after-new-session", "display-message 'server-hook-triggered'")
    new_session = server.new_session(session_name="trigger-hook", detach=True)
    assert "server-hook-triggered" in server.capture_pane()

    # Test session-level hooks
    session.set_hook("session-created", "display-message 'session-hook-triggered'")
    another_session = server.new_session(session_name="session-hook-test", detach=True)
    assert "session-hook-triggered" in server.capture_pane()

    # Test window-level hooks
    window.set_hook("window-linked", "display-message 'window-hook-triggered'")
    new_window = session.new_window()
    assert "window-hook-triggered" in server.capture_pane()

    # Test pane-level hooks
    pane.set_hook("pane-focus", "display-message 'pane-hook-triggered'")
    new_pane = window.split_window()
    window.select_pane(new_pane)
    assert "pane-hook-triggered" in server.capture_pane()

    # List variables

You may need to:

  1. Import any additional required modules or constants
  2. Adjust the hook names and trigger conditions based on the specific tmux version being tested
  3. Add cleanup code to remove the hooks after testing
  4. Add error handling for cases where hooks might fail to trigger


# List variables
assert server.show_option("command-alias") == {
"choose-session": "choose-tree -s",
"choose-window": "choose-tree -w",
"info": "show-messages -JT",
"server-info": "show-messages -JT",
"split-pane": "split-window",
"splitp": "split-window",
}
Comment on lines +464 to +471
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test edge cases and error conditions

The tests should cover edge cases such as empty values, invalid option names, and other error conditions to ensure that the option management functionality is robust.

Suggested implementation:

def test_stable_baseline_options_and_hooks(server: Server) -> None:
    """Ensure stable baseline across tmux versions and handle edge cases."""
    session = server.new_session(session_name="test", detach=True)

    # Test invalid option name
    with pytest.raises(TmuxCommandError):
        server.show_option("non-existent-option")

    # Test empty option value (setting and getting)
    server.set_option("status-left", "")
    assert server.show_option("status-left") == ""

    # List variables

You'll need to:

  1. Import pytest and TmuxCommandError at the top of the file if not already imported
  2. Make sure the Server class has set_option method available
  3. Consider adding more specific error message assertions in the pytest.raises check if the error messages are stable across tmux versions

if has_gte_version("3.2"):
assert server.show_option("terminal-features") == {
"screen*": [
"title",
],
"xterm*": [
"clipboard",
"ccolour",
"cstyle",
"focus",
"title",
],
}
assert server.show_option("terminal-overrides") is None
assert server.show_option("user-keys") is None
assert server.show_option("status-format") is None
assert server.show_option("update-environment") is None

# List variables: Pane
pane = session.active_pane
assert pane is not None
assert pane.show_option("pane-colours") is None


def test_high_level_api_expectations(server: Server) -> None:
"""Ensure options and hooks behave as expected."""

# Raw input and output
# Should be able to functionally parse raw CLI output, even outside of libtmux into
# options.

# Parsing steps
# 1. Basic KV split: Should split options into key,values.
# 2. Structure: Should decompose array-like options and dictionaries
# In the case of sparse arrays, which don't exist in Python, a SparseArray is
# used that behaves like a list but allows for sparse indexes so the indices
# aren't lost but the shape is still respected.
# 3. Python Typings: Should cast the fully structured objects into types
0