Tables And Cells⚓︎
table
⚓︎
Source-aware table values used by parsing and table transformations.
The public schema API accepts ordinary list[list[str]] values because that
is what pytest-bdd supplies to step functions. Internally, every raw string is
wrapped in :class:TableCell so later stages can report the location of the
original feature-file cell.
Projects that implement a custom table transformation may use these classes
directly. A transformed cell should normally be created with
source_cell.with_value(new_value). That keeps diagnostics attached to the
cell syntax the user actually wrote.
Info
Raw input is accepted as ordinary Sequence[Sequence[str]]. The parser
upgrades it to TableData before running transformations or schema
validation.
TableCell
dataclass
⚓︎
TableCell(
value: str,
source_row: int,
source_column: int,
source_value: str,
source_uri: str | None = None,
)
One current table value and the feature cell from which it originated.
Attributes:
-
value(str) –The value currently consumed by schema parsing. A transformer may change this value.
-
source_row(int) –One-based row number of the original Gherkin data table cell.
-
source_column(int) –One-based column number of the original Gherkin data table cell.
-
source_value(str) –The exact value before any table transformation.
-
source_uri(str | None) –URI of the source document when known.
A transformer may produce several cells from one source cell. Each new
cell can therefore have a different value while sharing the same
source location and source_value.
from_value
classmethod
⚓︎
Create an untransformed cell at a source location.
Parameters:
-
value(str) –Raw text from the table.
-
row(int) –One-based source row.
-
column(int) –One-based source column.
Returns:
-
TableCell–A
TableCellwhose current value and source value are the same.
Info
One-based coordinates match feature-file diagnostics and user expectations when reading Gherkin data tables.
with_value
⚓︎
Return a changed cell that still points to this cell's source.
This is the preferred way for a table transformer to replace or
expand syntax. For example, a source cell containing 3:Article
may produce three cells whose current value is Article while all
three still point back to the original 3:Article cell.
Parameters:
-
value(str) –New logical value consumed by later parsing stages.
Returns:
Warning
Constructing fresh cells manually can lose original coordinates. Use this method inside transformers whenever a logical value derives from an existing source cell.
TableData
dataclass
⚓︎
An immutable, source-aware representation of a Gherkin data table.
TableData intentionally provides only a few explicit operations. It is
not a second table-processing framework. Its job is to carry current cell
values and original source locations through the schema lifecycle.
Attributes:
-
rows(tuple[tuple[TableCell, ...], ...]) –Immutable rows of immutable
TableCelltuples. -
source_uri(str | None) –URI of the source document when known.
Info
Direct construction validates every cell and normalizes nested row sequences to tuples, so mutable input lists cannot change the stored table after construction.
__post_init__
⚓︎
Validate cells and normalize directly constructed rows to tuples.
from_rows
classmethod
⚓︎
Wrap ordinary string rows while recording source locations.
Parameters:
-
rows(RawTable) –Raw Gherkin data table rows, typically from pytest-bdd.
-
source(str | Path | None, default:None) –Optional URI string or filesystem path for provenance.
Returns:
-
TableData–A source-aware
TableDatainstance.
from_cells
classmethod
⚓︎
Build a table from cells whose source information already exists.
Custom transformers use this constructor after arranging existing or transformed cells into their new logical table shape.
Parameters:
-
rows(Sequence[Sequence[TableCell]]) –Logical rows of source-aware cells.
-
source(str | Path | None, default:None) –Optional URI string or filesystem path for provenance.
Returns:
-
TableData–A
TableDatainstance containing immutable row/cell tuples.
Warning
This constructor trusts that cells already preserve useful source
information. Prefer cell.with_value(...) when transforming.
ensure
classmethod
⚓︎
Return table as TableData.
Parameters:
-
table(RawTable | TableData) –Existing source-aware table or raw string rows.
Returns:
-
TableData–tableunchanged when already source-aware, otherwise a new -
TableData–TableDatacreated from raw rows.
Info
Schema parsing calls this at the boundary so downstream code can work only with source-aware cells.
cell
⚓︎
Return a cell using one-based row and column indexes.
One-based indexes match the coordinates shown in Gherkin data table errors and make transformer code easier to compare with a feature file.
Parameters:
Returns:
-
TableCell–The requested
TableCell.
Raises:
-
IndexError–If indexes are less than one or outside the table.
Warning
This helper is for human-facing coordinates. Use rows directly
for zero-based Python iteration.