Skip to content

Commit

Permalink
chore: remove doctest needs
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Aug 26, 2024
1 parent b134646 commit 6847b0e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/watchdog/utils/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ def method_name(method: MethodType) -> str:


def format_arg_value(arg_val: tuple[str, tuple[Any, ...]]) -> str:
"""Return a string representing a (name, value) pair.
>>> format_arg_value(("x", (1, 2, 3)))
'x=(1, 2, 3)'
"""
"""Return a string representing a (name, value) pair."""
arg, val = arg_val
return f"{arg}={val!r}"

Expand Down Expand Up @@ -152,17 +148,9 @@ def echo_class(klass: type, write: Callable = sys.stdout.write) -> None:
echo_instancemethod(klass, fn, write)


def echo_module(mod: MethodType, write: Callable = sys.stdout.write) -> None:
def echo_module(mod: MethodType, write: Callable[[str], int | None] = sys.stdout.write) -> None:
"""Echo calls to functions and methods in a module."""
for fname, fn in inspect.getmembers(mod, inspect.isfunction):
setattr(mod, fname, echo(fn, write))
for _, klass in inspect.getmembers(mod, inspect.isclass):
echo_class(klass, write)


if __name__ == "__main__":
import doctest

optionflags = doctest.ELLIPSIS
doctest.testfile("echoexample.txt", optionflags=optionflags)
doctest.testmod(optionflags=optionflags)
14 changes: 14 additions & 0 deletions tests/test_echo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Any

from watchdog.utils import echo
import pytest


@pytest.mark.parametrize(
("value", "expected"),
[
(("x", (1, 2, 3)), "x=(1, 2, 3)"),
],
)
def test_format_arg_value(value: tuple[str, tuple[Any, ...]], expected: str) -> None:
assert echo.format_arg_value(value) == expected

0 comments on commit 6847b0e

Please sign in to comment.