def test_visit_nodes_array():
    graph = {
        "abs": {
            "arguments": {
                "data": [{
                    "from_argument": "data"
                }, 10.0]
            },
            "process_id": "abs"
        },
        "cos": {
            "arguments": {
                "data": {
                    "from_node": "abs"
                }
            },
            "process_id": "cos",
            "result": True
        }
    }

    visitor = ProcessGraphVisitor()
    visitor.leaveProcess = MagicMock()
    visitor.enterArgument = MagicMock()
    visitor.enterArray = MagicMock()

    visitor.accept_process_graph(graph)
    assert visitor.leaveProcess.call_args_list == [
        call(process_id='abs', arguments=ANY),
        call(process_id='cos', arguments=ANY)
    ]
    assert visitor.enterArgument.call_args_list == [
        call(argument_id="data", value=ANY)
    ]
    assert visitor.enterArray.call_args_list == [call(argument_id="data")]
def test_visit_array_with_dereferenced_nodes():
    graph = {
        'arrayelement1': {
            'arguments': {
                'data': {
                    'from_argument': 'data'
                },
                'index': 2
            },
            'process_id': 'array_element',
            'result': False
        },
        'product1': {
            'process_id': 'product',
            'arguments': {
                'data': [{
                    'from_node': 'arrayelement1'
                }, -1]
            },
            'result': True
        }
    }
    top = ProcessGraphVisitor.dereference_from_node_arguments(graph)
    dereferenced = graph[top]
    assert dereferenced["arguments"]["data"][0]["arguments"]["data"][
        "from_argument"] == "data"

    visitor = ProcessGraphVisitor()
    visitor.leaveProcess = MagicMock()
    visitor.enterArgument = MagicMock()
    visitor.enterArray = MagicMock()
    visitor.arrayElementDone = MagicMock()
    visitor.constantArrayElement = MagicMock()

    visitor.accept(dereferenced)
    assert visitor.leaveProcess.call_args_list == [
        call(process_id='array_element', arguments=ANY),
        call(process_id='product', arguments=ANY)
    ]
    assert visitor.enterArgument.call_args_list == [
        call(argument_id="data", value={'from_argument': 'data'})
    ]
    assert visitor.enterArray.call_args_list == [call(argument_id="data")]
    assert visitor.arrayElementDone.call_args_list == [
        call({
            "process_id": "array_element",
            "arguments": {
                "data": {
                    "from_argument": "data"
                },
                "index": 2
            },
            "result": False
        })
    ]
    assert visitor.constantArrayElement.call_args_list == [call(-1)]
Пример #3
0
def test_visit_nodes():
    graph = {
        "abs": {
            "process_id": "abs",
            "arguments": {
                "data": {
                    "from_argument": "data"
                }
            },
        },
        "cos": {
            "process_id": "cos",
            "arguments": {
                "data": {
                    "from_node": "abs"
                },
                "data2": {
                    "from_parameter": "x"
                }
            },
            "result": True
        }
    }
    visitor = ProcessGraphVisitor()
    visitor.leaveProcess = MagicMock()
    visitor.enterArgument = MagicMock()
    visitor.from_parameter = MagicMock()

    visitor.accept_process_graph(graph)

    assert visitor.leaveProcess.call_args_list == [
        call(process_id="abs", arguments=ANY),
        call(process_id="cos", arguments=ANY),
    ]
    assert visitor.enterArgument.call_args_list == [
        call(argument_id="data", value=ANY),
        call(argument_id="data", value={"from_argument": "data"}),
        call(argument_id='data2', value={'from_parameter': 'x'})
    ]
    assert visitor.from_parameter.call_args_list == [
        call("x")
    ]
    def test_visit_nodes_array(self):
        graph = {
            "abs": {
                "arguments": {
                    "data": [{
                        "from_argument": "data"
                    }, 10.0]
                },
                "process_id": "abs"
            },
            "cos": {
                "arguments": {
                    "data": {
                        "from_node": "abs"
                    }
                },
                "process_id": "cos",
                "result": True
            }
        }
        original = ProcessGraphVisitor()

        leaveProcess = MagicMock(original.leaveProcess)
        original.leaveProcess = leaveProcess

        enterArgument = MagicMock(original.enterArgument)
        original.enterArgument = enterArgument

        arrayStart = MagicMock(original.enterArray)
        original.enterArray = arrayStart

        original.accept_process_graph(graph)
        self.assertEqual(2, leaveProcess.call_count)
        leaveProcess.assert_has_calls([call('abs', ANY), call('cos', ANY)])

        self.assertEqual(1, enterArgument.call_count)
        enterArgument.assert_has_calls([call('data', ANY)])

        self.assertEqual(1, arrayStart.call_count)
        arrayStart.assert_has_calls([call('data')])

        print(leaveProcess)
    def test_visit_nodes(self):
        graph = {
            "abs": {
                "arguments": {
                    "data": {
                        "from_argument": "data"
                    }
                },
                "process_id": "abs"
            },
            "cos": {
                "arguments": {
                    "data": {
                        "from_node": "abs"
                    }
                },
                "process_id": "cos",
                "result": True
            }
        }
        original = ProcessGraphVisitor()

        leaveProcess = MagicMock(original.leaveProcess)
        original.leaveProcess = leaveProcess

        enterArgument = MagicMock(original.enterArgument)
        original.enterArgument = enterArgument

        original.accept_process_graph(graph)
        assert leaveProcess.call_count == 2
        leaveProcess.assert_has_calls([call('abs', ANY), call('cos', ANY)])

        assert enterArgument.call_count == 2
        enterArgument.assert_has_calls([call('data', ANY), call('data', ANY)])

        print(leaveProcess)