示例#1
0
def test_nested_parallel_example():
    nested_level_1 = Parallel('NestedStateLevel1')
    nested_level_1.add_branch(Succeed('NestedStateLevel2'))

    first_state = Parallel('FirstState')
    first_state.add_branch(nested_level_1)

    result = Graph(first_state,
                   comment='This is a test.',
                   version='1.0',
                   timeout_seconds=3600).to_dict()
    assert result == {
        'StartAt': 'FirstState',
        'Comment': 'This is a test.',
        'Version': '1.0',
        'TimeoutSeconds': 3600,
        'States': {
            'FirstState': {
                'Type':
                'Parallel',
                'Branches': [{
                    'StartAt': 'NestedStateLevel1',
                    'States': {
                        'NestedStateLevel1': {
                            'Type':
                            'Parallel',
                            'Branches': [{
                                'StartAt': 'NestedStateLevel2',
                                'States': {
                                    'NestedStateLevel2': {
                                        'Type': 'Succeed'
                                    }
                                }
                            }],
                            'End':
                            True
                        }
                    }
                }],
                'End':
                True
            }
        }
    }
def test_parallel_state_creation():
    parallel_state = Parallel('Parallel')
    parallel_state.add_branch(Pass('Branch 1'))
    parallel_state.add_branch(Pass('Branch 2'))
    parallel_state.add_branch(Pass('Branch 3'))
    assert parallel_state.type == 'Parallel'
    assert len(parallel_state.branches) == 3
    assert parallel_state.to_dict() == {
        'Type': 'Parallel',
        'Branches': [
            {
                'StartAt': 'Branch 1',
                'States': {
                    'Branch 1': {
                        'Type': 'Pass',
                        'End': True
                    }
                }
            },
            {
                'StartAt': 'Branch 2',
                'States': {
                    'Branch 2': {
                        'Type': 'Pass',
                        'End': True
                    }
                }
            },
            {
                'StartAt': 'Branch 3',
                'States': {
                    'Branch 3': {
                        'Type': 'Pass',
                        'End': True
                    }
                }
            }
        ],
        'End': True
    }
def test_parallel_state_add_catch_adds_catcher_to_catchers(
        catch, expected_catch):
    step = Parallel('Parallel')
    step.add_catch(catch)
    assert step.to_dict()['Catch'] == expected_catch
def test_parallel_state_constructor_with_catch_adds_catcher_to_catchers(
        catch, expected_catch):
    step = Parallel('Parallel', catch=catch)
    assert step.to_dict()['Catch'] == expected_catch
def test_parallel_state_add_retry_adds_retrier_to_retriers(
        retry, expected_retry):
    step = Parallel('Parallel')
    step.add_retry(retry)
    assert step.to_dict()['Retry'] == expected_retry
def test_parallel_state_constructor_with_retry_adds_retrier_to_retriers(
        retry, expected_retry):
    step = Parallel('Parallel', retry=retry)
    assert step.to_dict()['Retry'] == expected_retry
示例#7
0
def test_parallel_state_with_placeholders():
    workflow_input = ExecutionInput()

    parallel_state = Parallel('ParallelState01')

    branch_A = Pass('Branch_A',
                    parameters={
                        'ParamA': parallel_state.output()['A']["B"],
                        'ParamB': workflow_input["Key01"]
                    })

    branch_B = Pass('Branch_B',
                    parameters={
                        'ParamA':
                        "TestValue",
                        'ParamB':
                        parallel_state.output()["Response"]["Key"]["State"]
                    })

    branch_C = Pass('Branch_C',
                    parameters={
                        'ParamA':
                        parallel_state.output()['A']["B"].get("C", float),
                        'ParamB': "HelloWorld"
                    })

    parallel_state.add_branch(branch_A)
    parallel_state.add_branch(branch_B)
    parallel_state.add_branch(branch_C)

    workflow_definition = Chain([parallel_state])
    result = Graph(workflow_definition).to_dict()

    expected_repr = {
        "StartAt": "ParallelState01",
        "States": {
            "ParallelState01": {
                "Type":
                "Parallel",
                "End":
                True,
                "Branches": [{
                    "StartAt": "Branch_A",
                    "States": {
                        "Branch_A": {
                            "Parameters": {
                                "ParamA.$": "$['A']['B']",
                                "ParamB.$": "$$.Execution.Input['Key01']"
                            },
                            "Type": "Pass",
                            "End": True
                        }
                    }
                }, {
                    "StartAt": "Branch_B",
                    "States": {
                        "Branch_B": {
                            "Parameters": {
                                "ParamA": "TestValue",
                                "ParamB.$": "$['Response']['Key']['State']"
                            },
                            "Type": "Pass",
                            "End": True
                        }
                    }
                }, {
                    "StartAt": "Branch_C",
                    "States": {
                        "Branch_C": {
                            "Parameters": {
                                "ParamA.$": "$['A']['B']['C']",
                                "ParamB": "HelloWorld"
                            },
                            "Type": "Pass",
                            "End": True
                        }
                    }
                }]
            }
        }
    }

    assert result == expected_repr
def test_parallel_state_with_placeholders():
    workflow_input = ExecutionInput()
    step_result = StepResult()

    parallel_state = Parallel(state_id="ParallelState01",
                              result_selector={
                                  "foo": step_result["foo"],
                                  "bar": step_result["bar1"]["bar2"]
                              })

    branch_A = Pass("Branch_A",
                    parameters={
                        "ParamA": parallel_state.output()["A"]["B"],
                        "ParamB": workflow_input["Key01"]
                    })

    branch_B = Pass("Branch_B",
                    parameters={
                        "ParamA":
                        "TestValue",
                        "ParamB":
                        parallel_state.output()["Response"]["Key"]["State"]
                    })

    branch_C = Pass("Branch_C",
                    parameters={
                        "ParamA":
                        parallel_state.output()["A"]["B"].get("C", float),
                        "ParamB": "HelloWorld"
                    })

    parallel_state.add_branch(branch_A)
    parallel_state.add_branch(branch_B)
    parallel_state.add_branch(branch_C)

    workflow_definition = Chain([parallel_state])
    result = Graph(workflow_definition).to_dict()

    expected_repr = {
        "StartAt": "ParallelState01",
        "States": {
            "ParallelState01": {
                "Type":
                "Parallel",
                "ResultSelector": {
                    "foo.$": "$['foo']",
                    "bar.$": "$['bar1']['bar2']"
                },
                "End":
                True,
                "Branches": [{
                    "StartAt": "Branch_A",
                    "States": {
                        "Branch_A": {
                            "Parameters": {
                                "ParamA.$": "$['A']['B']",
                                "ParamB.$": "$$.Execution.Input['Key01']"
                            },
                            "Type": "Pass",
                            "End": True
                        }
                    }
                }, {
                    "StartAt": "Branch_B",
                    "States": {
                        "Branch_B": {
                            "Parameters": {
                                "ParamA": "TestValue",
                                "ParamB.$": "$['Response']['Key']['State']"
                            },
                            "Type": "Pass",
                            "End": True
                        }
                    }
                }, {
                    "StartAt": "Branch_C",
                    "States": {
                        "Branch_C": {
                            "Parameters": {
                                "ParamA.$": "$['A']['B']['C']",
                                "ParamB": "HelloWorld"
                            },
                            "Type": "Pass",
                            "End": True
                        }
                    }
                }]
            }
        }
    }

    assert result == expected_repr