8000 Docs: Tested doc examples by tony · Pull Request #581 · tmux-python/libtmux · GitHub
[go: up one dir, main page]

Skip to content

Docs: Tested doc examples #581

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

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
39 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
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
9695bdf
tests(test_waiter[capture_pane]): Add resiliency for CI test grid
tony Feb 28, 2025
cf08043
tests(test_waiter[exact_match]): Skip flaky exact match test on tmux …
tony Feb 28, 2025
7db6426
test(waiter): Replace assertions with warning-based checks in detaile…
tony Feb 28, 2025
463b9c3
pyproject(mypy[test.examples.pytest_plugin]): pytest examples to igno…
tony Feb 26, 2025
f768e53
docs: Improve window.py
tony Feb 1, 2025
9020e14
docs: Improve session.py
tony Feb 1, 2025
5a41553
docs: Improve server.py
tony Feb 1, 2025
ca20738
docs: Improve pane.py
tony Feb 1, 2025
1ccd708
docs: Improve neo.py
tony Feb 1, 2025
2c1182a
docs: Improve test.py
tony Feb 1, 2025
431985e
docs: Improve common.py
tony Feb 1, 2025
002df05
docs: Improve exc.py
tony Feb 1, 2025
355d0bf
docs: Improve pytest_plugin.py
tony Feb 1, 2025
238d6d2
docs: Improve conftest.py
tony Feb 1, 2025
626f024
docs/tests: Add `server` doctest examples
tony Feb 15, 2025
38182be
fix(Server): update Server.windows doctest to be environment-agnostic
tony Feb 26, 2025
73b4a2c
docs: Add new Topics
tony Feb 26, 2025
0add0be
docs(topics): Improve documentation with executable examples
tony Feb 26, 2025
2248328
docs(README): Enhance project README with comprehensive overview
tony Feb 26, 2025
2a2b6ff
docs,tests(pytest plugin) Examples
tony Feb 26, 2025
14c4b27
!squash docs topics
tony Feb 28, 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
docs: Improve exc.py
  • Loading branch information
tony committed Feb 28, 2025
commit 002df059105556abf0e6b4c79c5c57abdb058379
79 changes: 45 additions & 34 deletions src/libtmux/exc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
"""libtmux exceptions.
"""Provide exceptions used by libtmux.

libtmux.exc
~~~~~~~~~~~

This module implements exceptions used throughout libtmux for error
handling in sessions, windows, panes, and general usage. It preserves
existing exception definitions for backward compatibility and does not
remove any doctests.

Notes
-----
Exceptions in this module inherit from :exc:`LibTmuxException` or
specialized base classes to form a hierarchy of tmux-related errors.
"""

from __future__ import annotations
Expand All @@ -16,19 +25,19 @@


class LibTmuxException(Exception):
"""Base Exception for libtmux Errors."""
"""Base exception for all libtmux errors."""


class TmuxSessionExists(LibTmuxException):
"""Session does not exist in the server."""
"""Raised if a tmux session with the requested name already exists."""


class TmuxCommandNotFound(LibTmuxException):
"""Application binary for tmux not found."""
"""Raised when the tmux binary cannot be found on the system."""


class TmuxObjectDoesNotExist(ObjectDoesNotExist):
"""The query returned multiple objects when only one was expected."""
"""Raised when a tmux object cannot be found in the server output."""

def __init__(
self,
Expand All @@ -39,19 +48,20 @@ def __init__(
*args: object,
) -> None:
if all(arg is not None for arg in [obj_key, obj_id, list_cmd, list_extra_args]):
return super().__init__(
super().__init__(
f"Could not find {obj_key}={obj_id} for {list_cmd} "
f"{list_extra_args if list_extra_args is not None else ''}",
)
return super().__init__("Could not find object")
else:
super().__init__("Could not find object")


class VersionTooLow(LibTmuxException):
"""Raised if tmux below the minimum version to use libtmux."""
"""Raised if the installed tmux version is below the minimum required."""


class BadSessionName(LibTmuxException):
"""Disallowed session name for tmux (empty, contains periods or colons)."""
"""Raised if a tmux session name is disallowed (e.g., empty, has colons/periods)."""

def __init__(
self,
Expand All @@ -62,83 +72,84 @@ def __init__(
msg = f"Bad session name: {reason}"
if session_name is not None:
msg += f" (session name: {session_name})"
return super().__init__(msg)
super().__init__(msg)


class OptionError(LibTmuxException):
"""Root error for any error involving invalid, ambiguous or bad options."""
"""Base exception for errors involving invalid, ambiguous, or unknown options."""


class UnknownOption(OptionError):
"""Option unknown to tmux show-option(s) or show-window-option(s)."""
"""Raised if tmux reports an unknown option."""


class UnknownColorOption(UnknownOption):
"""Unknown color option."""
"""Raised if a server color option is unknown (must be 88 or 256)."""

def __init__(self, *args: object) -> None:
return super().__init__("Server.colors must equal 88 or 256")
super().__init__("Server.colors must equal 88 or 256")


class InvalidOption(OptionError):
"""Option invalid to tmux, introduced in tmux v2.4."""
"""Raised if tmux reports an invalid option (tmux >= 2.4)."""


class AmbiguousOption(OptionError):
"""Option that could potentially match more than one."""
"""Raised if tmux reports an option that could match more than one."""


class WaitTimeout(LibTmuxException):
"""Function timed out without meeting condition."""
"""Raised when a function times out waiting for a condition."""


class VariableUnpackingError(LibTmuxException):
"""Error unpacking variable."""
"""Raised when an environment variable cannot be unpacked as expected."""

def __init__(self, variable: t.Any | None = None, *args: object) -> None:
return super().__init__(f"Unexpected variable: {variable!s}")
super().__init__(f"Unexpected variable: {variable!s}")


class PaneError(LibTmuxException):
"""Any type of pane related error."""
"""Base exception for pane-related errors."""


class PaneNotFound(PaneError):
"""Pane not found."""
"""Raised if a specified pane cannot be found."""

def __init__(self, pane_id: str | None = None, *args: object) -> None:
if pane_id is not None:
return super().__init__(f"Pane not found: {pane_id}")
return super().__init__("Pane not found")
super().__init__(f"Pane not found: {pane_id}")
else:
super().__init__("Pane not found")


class WindowError(LibTmuxException):
"""Any type of window related error."""
"""Base exception for window-related errors."""


class MultipleActiveWindows(WindowError):
"""Multiple active windows."""
"""Raised if multiple active windows are detected (where only one is expected)."""

def __init__(self, count: int, *args: object) -> None:
return super().__init__(f"Multiple active windows: {count} found")
super().__init__(f"Multiple active windows: {count} found")


class NoActiveWindow(WindowError):
"""No active window found."""
"""Raised if no active window exists when one is expected."""

def __init__(self, *args: object) -> None:
return super().__init__("No active windows found")
super().__init__("No active windows found")


class NoWindowsExist(WindowError):
"""No windows exist for object."""
"""Raised if a session or server has no windows."""

def __init__(self, *args: object) -> None:
return super().__init__("No windows exist for object")
super().__init__("No windows exist for object")


class AdjustmentDirectionRequiresAdjustment(LibTmuxException, ValueError):
"""If *adjustment_direction* is set, *adjustment* must be set."""
"""Raised if an adjustment direction is set, but no adjustment value is provided."""

def __init__(self) -> None:
super().__init__("adjustment_direction requires adjustment")
Expand All @@ -148,18 +159,18 @@ class WindowAdjustmentDirectionRequiresAdjustment(
WindowError,
AdjustmentDirectionRequiresAdjustment,
):
"""ValueError for :meth:`libtmux.Window.resize_window`."""
"""Raised if window resizing requires an adjustment value, but none is provided."""


class PaneAdjustmentDirectionRequiresAdjustment(
WindowError,
AdjustmentDirectionRequiresAdjustment,
):
"""ValueError for :meth:`libtmux.Pane.resize_pane`."""
"""Raised if pane resizing requires an adjustment value, but none is provided."""


class RequiresDigitOrPercentage(LibTmuxException, ValueError):
"""Requires digit (int or str digit) or a percentage."""
"""Raised if a sizing argument must be a digit or a percentage."""

def __init__(self) -> None:
super().__init__("Requires digit (int or str digit) or a percentage.")
0