diff --git a/stubs/behave/behave/model.pyi b/stubs/behave/behave/model.pyi new file mode 100644 index 000000000000..85065b6ca917 --- /dev/null +++ b/stubs/behave/behave/model.pyi @@ -0,0 +1,72 @@ +from _typeshed import Incomplete +from collections import OrderedDict +from collections.abc import Iterable, Iterator, Mapping, Sequence +from typing import ClassVar, TypeAlias, TypeVar, overload +from typing_extensions import Never, Self + +from behave.model_core import Replayable + +_T = TypeVar("_T") + +# A table row, either already parsed or as a plain list of cell values. +_RowData: TypeAlias = Row | list[str] + +class Table(Replayable): + type: ClassVar[str] + headings: list[str] + rows: list[Row] + line: int + modified: bool + def __init__(self, headings: list[str], rows: Iterable[_RowData] | None = None, line: int | None = None) -> None: ... + def clear(self, headings: list[str] | None = None, keep_headings: bool = True) -> None: ... + def add_row(self, row: _RowData, line: int | None = None) -> None: ... + def add_column(self, column_name: str, values: Iterable[str] | None = None, default_value: str = "") -> int: ... + def remove_column(self, column_name_or_index: str | int) -> None: ... + def remove_columns(self, column_names: Iterable[str]) -> None: ... + def has_column(self, column_name: str) -> bool: ... + def get_column_index(self, column_name: str) -> int: ... + def require_column(self, column_name: str) -> int: ... + def require_columns(self, column_names: Iterable[str]) -> None: ... + def ensure_column_exists(self, column_name: str) -> int: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __iter__(self) -> Iterator[Row]: ... + + @overload + def __getitem__(self, index: int) -> Row: ... + @overload + def __getitem__(self, index: slice) -> list[Row]: ... + + # Always raises: the comparison is asserted and then `NotImplementedError` is raised. + def assert_equals(self, data: object) -> Never: ... + @classmethod + def from_dicts(cls, headings: list[str], table_data: Sequence[dict[str, str]], line: int | None = None) -> Self: ... + @classmethod + def from_data( + cls, headings: list[str], table_data: Sequence[dict[str, str] | _RowData] | None = None, line: int = 0 + ) -> Table: ... + +class Row: + headings: list[str] + cells: list[str] + line: int | None + comments: Incomplete | None + def __init__(self, headings: list[str], cells: list[str], line: int | None = None, comments=None) -> None: ... + def __getitem__(self, name: str | int) -> str: ... + def __contains__(self, item: str) -> bool: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[str]: ... + def items(self) -> zip[tuple[str, str]]: ... + + @overload + def get(self, key: str | int, default: None = None) -> str | None: ... + @overload + def get(self, key: str | int, default: _T) -> str | _T: ... + + def as_dict(self) -> OrderedDict[str, str]: ... + @classmethod + def from_dict(cls, headings: list[str], row_data: Mapping[str, str], *, line: int | None = None, comments=None) -> Self: ... + +def __getattr__(name: str) -> Incomplete: ... diff --git a/stubs/behave/behave/model_core.pyi b/stubs/behave/behave/model_core.pyi new file mode 100644 index 000000000000..f2b1bc5d94d5 --- /dev/null +++ b/stubs/behave/behave/model_core.pyi @@ -0,0 +1,8 @@ +from _typeshed import Incomplete +from typing import ClassVar + +class Replayable: + type: ClassVar[str | None] + def replay(self, formatter) -> None: ... + +def __getattr__(name: str) -> Incomplete: ... diff --git a/stubs/behave/behave/runner.pyi b/stubs/behave/behave/runner.pyi index a3abfa2d0de2..c3d3e7f792f5 100644 --- a/stubs/behave/behave/runner.pyi +++ b/stubs/behave/behave/runner.pyi @@ -3,6 +3,8 @@ from collections.abc import Callable from contextlib import AbstractContextManager from typing import ClassVar, ParamSpec +from behave.model import Row, Table + _P = ParamSpec("_P") class Context: @@ -14,10 +16,10 @@ class Context: tags: set[str] aborted: bool failed: bool - table: Incomplete | None + table: Table | None text: str | None config: Incomplete - active_outline: Incomplete + active_outline: Row | None fail_on_cleanup_errors: bool def __init__(self, runner) -> None: ...