def test_pipeline_variable_in_pipeline_definition(sagemaker_session):
    param_str = ParameterString(name="MyString", default_value="1")
    param_int = ParameterInteger(name="MyInteger", default_value=3)

    property_file = PropertyFile(
        name="name",
        output_name="result",
        path="output",
    )
    json_get_func2 = JsonGet(
        step_name="my-step",
        property_file=property_file,
        json_path="my-json-path",
    )
    prop = Properties("Steps.MyStep", "DescribeProcessingJobResponse")

    cond = ConditionGreaterThan(left=param_str, right=param_int.to_string())
    step_fail = FailStep(
        name="MyFailStep",
        error_message=Join(
            on=" ",
            values=[
                "Execution failed due to condition check fails, see:",
                json_get_func2.to_string(),
                prop.ProcessingOutputConfig.Outputs["MyOutputName"].S3Output.
                S3Uri.to_string(),
                param_int,
            ],
        ),
    )
    step_cond = ConditionStep(
        name="MyCondStep",
        conditions=[cond],
        if_steps=[],
        else_steps=[step_fail],
    )
    pipeline = Pipeline(
        name="MyPipeline",
        parameters=[param_str, param_int],
        steps=[step_cond],
        sagemaker_session=sagemaker_session,
    )

    dsl = json.loads(pipeline.definition())
    assert dsl["Parameters"] == [
        {
            "Name": "MyString",
            "Type": "String",
            "DefaultValue": "1"
        },
        {
            "Name": "MyInteger",
            "Type": "Integer",
            "DefaultValue": 3
        },
    ]
    assert len(dsl["Steps"]) == 1
    assert dsl["Steps"][0] == {
        "Name": "MyCondStep",
        "Type": "Condition",
        "Arguments": {
            "Conditions": [
                {
                    "Type": "GreaterThan",
                    "LeftValue": {
                        "Get": "Parameters.MyString"
                    },
                    "RightValue": {
                        "Std:Join": {
                            "On": "",
                            "Values": [{
                                "Get": "Parameters.MyInteger"
                            }],
                        },
                    },
                },
            ],
            "IfSteps": [],
            "ElseSteps": [{
                "Name": "MyFailStep",
                "Type": "Fail",
                "Arguments": {
                    "ErrorMessage": {
                        "Std:Join": {
                            "On":
                            " ",
                            "Values": [
                                "Execution failed due to condition check fails, see:",
                                {
                                    "Std:Join": {
                                        "On":
                                        "",
                                        "Values": [
                                            {
                                                "Std:JsonGet": {
                                                    "PropertyFile": {
                                                        "Get":
                                                        "Steps.my-step.PropertyFiles.name"
                                                    },
                                                    "Path": "my-json-path",
                                                }
                                            },
                                        ],
                                    },
                                },
                                {
                                    "Std:Join": {
                                        "On":
                                        "",
                                        "Values": [
                                            {
                                                "Get":
                                                "Steps.MyStep.ProcessingOutputConfig."
                                                +
                                                "Outputs['MyOutputName'].S3Output.S3Uri"
                                            },
                                        ],
                                    },
                                },
                                {
                                    "Get": "Parameters.MyInteger"
                                },
                            ],
                        }
                    }
                },
            }],
        },
    }
def test_ppl_var_to_string_and_add(sagemaker_session, role, pipeline_name):
    param_str = ParameterString(name="MyString", default_value="1")
    param_int = ParameterInteger(name="MyInteger", default_value=3)

    cond = ConditionGreaterThan(left=param_str, right=param_int.to_string())
    step_cond = ConditionStep(
        name="CondStep",
        conditions=[cond],
        if_steps=[],
        else_steps=[],
    )
    join_fn1 = Join(
        on=" ",
        values=[
            "condition greater than check return:",
            step_cond.properties.Outcome.to_string(),
            "and left side param str is",
            param_str,
            "and right side param int is",
            param_int,
        ],
    )

    step_fail = FailStep(
        name="FailStep",
        error_message=join_fn1,
    )
    pipeline = Pipeline(
        name=pipeline_name,
        parameters=[param_str, param_int],
        steps=[step_cond, step_fail],
        sagemaker_session=sagemaker_session,
    )

    try:
        response = pipeline.create(role)
        pipeline_arn = response["PipelineArn"]
        execution = pipeline.start()
        response = execution.describe()
        assert response["PipelineArn"] == pipeline_arn

        try:
            execution.wait(delay=30, max_attempts=60)
        except WaiterError:
            pass
        execution_steps = execution.list_steps()

        assert len(execution_steps) == 2
        for execution_step in execution_steps:
            if execution_step["StepName"] == "CondStep":
                assert execution_step["StepStatus"] == "Succeeded"
                continue
            assert execution_step["StepName"] == "FailStep"
            assert execution_step["StepStatus"] == "Failed"
            assert (
                execution_step["FailureReason"] ==
                "condition greater than check return: false "
                "and left side param str is 1 and right side param int is 3")

        # Update int param to update cond step outcome
        execution = pipeline.start(parameters={"MyInteger": 0})
        try:
            execution.wait(delay=30, max_attempts=60)
        except WaiterError:
            pass
        execution_steps = execution.list_steps()

        assert len(execution_steps) == 2
        for execution_step in execution_steps:
            if execution_step["StepName"] == "CondStep":
                assert execution_step["StepStatus"] == "Succeeded"
                continue
            assert execution_step["StepName"] == "FailStep"
            assert execution_step["StepStatus"] == "Failed"
            assert (
                execution_step["FailureReason"] ==
                "condition greater than check return: true "
                "and left side param str is 1 and right side param int is 0")
    finally:
        try:
            pipeline.delete()
        except Exception:
            pass