text_lint.linter.states.assertion.AssertionState

class text_lint.linter.states.assertion.AssertionState(linter: Linter)[source]

Bases: StateBase

State for assertion operations.

__init__(linter: Linter) None[source]

Initialize AssertionState instances.

Parameters:

linter (Linter) – The linter instance being encapsulated.

fail(expected: str) None[source]

Raise an exception indicating this operation has failed.

Parameters:

expected (str) – The value the assertion operation was expecting.

loop(assertions: List[AssertionBase], count: int) None[source]

Start a looped sequence of assertions after the current operation.

Parameters:
  • assertions (List[AssertionBase]) – A list of assertion operations to loop over.

  • count (int) – The number of times to repeat these operations.

next() str[source]

Read the next line from the text file.

Returns:

The next line from the text file.

Return type:

str

rewind() str[source]

Rewind the text file so another assertion can try matching.

Returns:

The previous line the text file has been rewound to.

Raises:

AssertionLogicError (if invoked twice in a row)

Return type:

str

save(matches: Match[str] | Sequence[Match[str]]) None[source]

Save the given regex match group(s).

Parameters:

matches (Match[str] | Sequence[Match[str]]) – A list or individual regex match object to save.