Skip to content

testing

Unit testing stage implementation for CheckMate

Classes

TestStage

Bases: BaseStage[TestStageState]

Flexible stage implementation for testing

Attributes:

Attributes

execute_error class-attribute instance-attribute
execute_error: int | None = None
execute_sleep class-attribute instance-attribute
execute_sleep: int = 0
modify_status class-attribute instance-attribute
modify_status: StageStatus | None = None
rollback_error class-attribute instance-attribute
rollback_error: bool = False
set_data class-attribute instance-attribute
set_data: Any | None = None
set_result class-attribute instance-attribute
set_result: TestStageStateResult | None = None

Functions

execute_stage
execute_stage() -> None

Executes the stage.

Raises:

Example
stage = TestStage(execute_error=1)
try:
    stage.execute_stage()
except TestStageError as e:
    print(e)
get_test_data
get_test_data() -> Any | None

Gets the test data for the stage.

Returns:

  • Any | None

    Any | None: The test data for the stage, or None if not set.

Example
stage = TestStage(set_data="test_data")
stage.execute_stage()
data = stage.get_test_data()
print(data)  # Output: test_data
rollback_stage
rollback_stage() -> None

Rolls back the stage.

Raises:

Example
stage = TestStage(rollback_error=True)
try:
    stage.rollback_stage()
except TestStageRollbackError as e:
    print(e)

TestStageError

Bases: Exception

Custom exception for testing

This exception is raised during the execution of a stage to simulate an error.

Example
if some_condition:
    raise TestStageError("An error occurred during stage execution")

TestStageRollbackError

Bases: Exception

Custom exception for testing

This exception is raised during the rollback of a stage to simulate an error.

Example
if some_condition:
    raise TestStageRollbackError("An error occurred during stage rollback")

TestStageState

Bases: BaseStageState[TestStageStateResult]

Flexible state data model for testing

Attributes:

  • data (Dict) –

    A dictionary to store state data.

Attributes

data class-attribute instance-attribute
data: Dict = Field(
    default_factory=dict,
    title="State Data",
    description="A dictionary to store state data.",
)

TestStageStateResult

Bases: BaseModel

Flexible state data model for testing

Attributes:

  • result_data (Dict) –

    A dictionary to store result data.

Attributes

result_data class-attribute instance-attribute
result_data: Dict = Field(
    default_factory=dict,
    title="Result Data",
    description="A dictionary to store result data.",
)