Skip to content

test_model_runner

Tests for ModelRunner class

test_run_model_with_invalid_model_should_fail()

Test that model runner puts an invalid model (a model that fails the validate method) into the Failed model state during run_model

Source code in tests/business/workflow/test_model_runner.py
def test_run_model_with_invalid_model_should_fail():
    """Test that model runner puts an invalid model (a model that
    fails the validate method) into the Failed model state during run_model"""

    # Arrange
    logger = Mock()
    model = Mock()

    model.validate.return_value = False

    # Act
    success = ModelRunner.run_model(model, logger)

    # Assert
    assert success is False
    assert model.status == ModelStatus.FAILED

test_run_model_with_model_throwing_exception_should_fail(method)

Test that model runner puts the model into the Failed state if an error occurred during the execution of the provided method

Source code in tests/business/workflow/test_model_runner.py
@pytest.mark.parametrize(
    "method",
    [
        "initialize",
        "execute",
        "finalize",
    ],
)
def test_run_model_with_model_throwing_exception_should_fail(method: str):
    """Test that model runner puts the model into the Failed state
    if an error occurred during the execution of the provided method"""

    # Arrange
    logger = Mock()
    model = Mock()

    method = getattr(model, method)
    method.side_effect = RuntimeError()

    model.validate.return_value = True

    # Act
    success = ModelRunner.run_model(model, logger)

    # Assert
    assert success is False
    assert model.status == ModelStatus.FAILED

test_run_model_with_valid_model_should_pass_all_model_stages()

Test a valid model goes through all the ModelStatus states (except for Failed state) during a run

Source code in tests/business/workflow/test_model_runner.py
def test_run_model_with_valid_model_should_pass_all_model_stages():
    """Test a valid model goes through all the ModelStatus states
    (except for Failed state) during a run"""

    # Arrange
    model = Mock()
    logger = Mock()

    # Act
    success = ModelRunner.run_model(model, logger)

    # Assert
    assert success
    assert model.status == ModelStatus.FINALIZED