def test_delete(make_stubber, error_code):
    stepfunctions_client = boto3.client('stepfunctions')
    stepfunctions_stubber = make_stubber(stepfunctions_client)
    state_machine = StepFunctionsStateMachine(stepfunctions_client)
    state_machine.state_machine_arn = 'test-state_machine_arn'

    stepfunctions_stubber.stub_delete_state_machine(
        state_machine.state_machine_arn, error_code=error_code)

    if error_code is None:
        state_machine.delete()
    else:
        with pytest.raises(ClientError) as exc_info:
            state_machine.delete()
        assert exc_info.value.response['Error']['Code'] == error_code
def destroy(state_machine_name, stack, cf_resource):
    """
    Destroys the state machine, the resources managed by the CloudFormation stack,
    and the CloudFormation stack itself.

    :param state_machine_name: The name of the state machine created for the demo.
    :param stack: The CloudFormation stack that manages the demo resources.
    :param cf_resource: A Boto3 CloudFormation resource.
    """
    print("Removing the state machine.")
    state_machine = StepFunctionsStateMachine(boto3.client('stepfunctions'))
    state_machine.find(state_machine_name)
    state_machine.delete()

    print(f"Deleting {stack.name}.")
    stack.delete()
    print("Waiting for stack removal.")
    waiter = cf_resource.meta.client.get_waiter('stack_delete_complete')
    waiter.wait(StackName=stack.name)
    print("Stack delete complete.")