pytest_beehave.reporter

Terminal reporting for pytest-beehave actions.

 1"""Terminal reporting for pytest-beehave actions."""
 2
 3from __future__ import annotations
 4
 5from typing import Protocol
 6
 7from pytest_beehave.bootstrap import BootstrapResult
 8
 9
10class TerminalWriterProtocol(Protocol):
11    """Protocol for a terminal writer."""
12
13    def line(self, text: str = "") -> None:  # pragma: no cover
14        """Write a line to the terminal."""
15        ...
16
17
18def report_bootstrap(writer: TerminalWriterProtocol, result: BootstrapResult) -> None:
19    """Report bootstrap actions to the terminal.
20
21    Args:
22        writer: Terminal writer to write to.
23        result: The bootstrap result.
24    """
25    for name in result.created_subfolders:
26        writer.line(f"[beehave] MKDIR {name}/")
27    for path in result.migrated_files:
28        writer.line(f"[beehave] MIGRATE {path}")
29    for warning in result.collision_warnings:
30        writer.line(f"[beehave] WARNING {warning}")
31
32
33def report_id_write_back(writer: TerminalWriterProtocol, errors: list[str]) -> None:
34    """Report ID write-back errors to the terminal.
35
36    Args:
37        writer: Terminal writer to write to.
38        errors: List of error strings from assign_ids.
39    """
40    for error in errors:
41        writer.line(f"[beehave] ERROR: {error}")
42
43
44def report_sync_actions(writer: TerminalWriterProtocol, actions: list[str]) -> None:
45    """Report sync actions to the terminal.
46
47    Args:
48        writer: Terminal writer to write to.
49        actions: List of action description strings.
50    """
51    for action in actions:
52        writer.line(f"[beehave] {action}")
class TerminalWriterProtocol(typing.Protocol):
11class TerminalWriterProtocol(Protocol):
12    """Protocol for a terminal writer."""
13
14    def line(self, text: str = "") -> None:  # pragma: no cover
15        """Write a line to the terminal."""
16        ...

Protocol for a terminal writer.

TerminalWriterProtocol(*args, **kwargs)
1960def _no_init_or_replace_init(self, *args, **kwargs):
1961    cls = type(self)
1962
1963    if cls._is_protocol:
1964        raise TypeError('Protocols cannot be instantiated')
1965
1966    # Already using a custom `__init__`. No need to calculate correct
1967    # `__init__` to call. This can lead to RecursionError. See bpo-45121.
1968    if cls.__init__ is not _no_init_or_replace_init:
1969        return
1970
1971    # Initially, `__init__` of a protocol subclass is set to `_no_init_or_replace_init`.
1972    # The first instantiation of the subclass will call `_no_init_or_replace_init` which
1973    # searches for a proper new `__init__` in the MRO. The new `__init__`
1974    # replaces the subclass' old `__init__` (ie `_no_init_or_replace_init`). Subsequent
1975    # instantiation of the protocol subclass will thus use the new
1976    # `__init__` and no longer call `_no_init_or_replace_init`.
1977    for base in cls.__mro__:
1978        init = base.__dict__.get('__init__', _no_init_or_replace_init)
1979        if init is not _no_init_or_replace_init:
1980            cls.__init__ = init
1981            break
1982    else:
1983        # should not happen
1984        cls.__init__ = object.__init__
1985
1986    cls.__init__(self, *args, **kwargs)
def line(self, text: str = '') -> None:
14    def line(self, text: str = "") -> None:  # pragma: no cover
15        """Write a line to the terminal."""
16        ...

Write a line to the terminal.

def report_bootstrap( writer: TerminalWriterProtocol, result: pytest_beehave.bootstrap.BootstrapResult) -> None:
19def report_bootstrap(writer: TerminalWriterProtocol, result: BootstrapResult) -> None:
20    """Report bootstrap actions to the terminal.
21
22    Args:
23        writer: Terminal writer to write to.
24        result: The bootstrap result.
25    """
26    for name in result.created_subfolders:
27        writer.line(f"[beehave] MKDIR {name}/")
28    for path in result.migrated_files:
29        writer.line(f"[beehave] MIGRATE {path}")
30    for warning in result.collision_warnings:
31        writer.line(f"[beehave] WARNING {warning}")

Report bootstrap actions to the terminal.

Args: writer: Terminal writer to write to. result: The bootstrap result.

def report_id_write_back( writer: TerminalWriterProtocol, errors: list[str]) -> None:
34def report_id_write_back(writer: TerminalWriterProtocol, errors: list[str]) -> None:
35    """Report ID write-back errors to the terminal.
36
37    Args:
38        writer: Terminal writer to write to.
39        errors: List of error strings from assign_ids.
40    """
41    for error in errors:
42        writer.line(f"[beehave] ERROR: {error}")

Report ID write-back errors to the terminal.

Args: writer: Terminal writer to write to. errors: List of error strings from assign_ids.

def report_sync_actions( writer: TerminalWriterProtocol, actions: list[str]) -> None:
45def report_sync_actions(writer: TerminalWriterProtocol, actions: list[str]) -> None:
46    """Report sync actions to the terminal.
47
48    Args:
49        writer: Terminal writer to write to.
50        actions: List of action description strings.
51    """
52    for action in actions:
53        writer.line(f"[beehave] {action}")

Report sync actions to the terminal.

Args: writer: Terminal writer to write to. actions: List of action description strings.