コード例 #1
0
    def test_eq_similar_network(self, pipes_list):
        network_a = ZeroNetwork(pipes_list)
        network_b = ZeroNetwork(list(pipes_list))

        assert id(network_a) != id(network_b)
        assert network_a.id != network_b.id
        assert network_a == network_b
コード例 #2
0
    def test_neq_network(self, pipes_list):
        first_batch, second_batch = _split_lists(pipes_list, 2)

        network_a = ZeroNetwork(first_batch)
        network_b = ZeroNetwork(second_batch)

        assert network_a != network_b
コード例 #3
0
    def test_output_nodes(self, pipes_list):
        network = ZeroNetwork()
        network.add_pipes(*pipes_list)

        assert list(network.input_nodes) == [
            pipe.node_a for pipe in pipes_list if pipe.node_b == ZeroNode.OUT
        ]
コード例 #4
0
    def test_or_network(self, nodes_list, pipes_list):
        pipes_list1, pipes_list2 = _split_lists(pipes_list, 2)

        network_a = ZeroNetwork(pipes_list1)
        network_b = ZeroNetwork(pipes_list2)

        network_c = network_a | network_b

        assert set(
            network_c.pipes) == set(network_a.pipes) | set(network_b.pipes)
コード例 #5
0
    def test_and_network(self, nodes_list, pipes_list):
        pipes_list1, pipes_list2 = _split_lists(pipes_list, 2, cross=True)

        network_a = ZeroNetwork(pipes_list1)
        network_b = ZeroNetwork(pipes_list2)

        network_c = network_a & network_b

        assert set(
            network_c.pipes) == set(network_a.pipes) & set(network_b.pipes)
コード例 #6
0
    def test_iand_network(self, nodes_list, pipes_list):
        pipes_list1, pipes_list2 = _split_lists(pipes_list, 2)

        network_a = ZeroNetwork(pipes_list1)
        network_b = ZeroNetwork(pipes_list2)

        network_c = network_a.copy()
        network_c &= network_b

        assert set(
            network_c.pipes) == set(network_a.pipes) & set(network_b.pipes)
コード例 #7
0
    def test_reverse_pipes_map(self, pipes_list):
        network = ZeroNetwork()
        network.add_pipes(*pipes_list)

        pipes_map = network.get_pipes_map(reverse=True)

        test_pipes_map = defaultdict(
            lambda: defaultdict(lambda: defaultdict(lambda: None)))

        for pipe in pipes_list:
            node_a = pipe.node_a.id if not isinstance(pipe.node_a,
                                                      str) else pipe.node_a
            node_b = pipe.node_b.id if not isinstance(pipe.node_b,
                                                      str) else pipe.node_b
            test_pipes_map[node_b][node_a][pipe.id] = pipe

        assert pipes_map == test_pipes_map
コード例 #8
0
    def test_remove_pipes(self, pipes_list):
        network = ZeroNetwork()
        pipes_list1, pipes_list2 = _split_lists(pipes_list, 2)
        network.add_pipes(*pipes_list)
        network.remove_pipes(*pipes_list1)

        assert list(network.pipes.values()) == list(pipes_list2)
コード例 #9
0
def get_network():
    hello_world_node = ZeroNode(
        hello_world_op,
        _id="hello_world_node_id",  # set custom id (default: uuid4)
    )

    print_node = ZeroNode(print)

    #                                        -------->  [print_node]
    #                                       |
    #   <in>  ----> [hello_world_node] ----
    #                                       \
    #                                         -------->  <out>
    return ZeroNetwork([
        ZeroPipe(ZeroNode.IN, hello_world_node),
        ZeroPipe(hello_world_node, print_node),
        ZeroPipe("hello_world_node_id", ZeroNode.OUT),
    ])
コード例 #10
0
def get_network():
    b = ZeroNode(RoundRobinBalancerOperator(), _id="balancer").save()
    n1 = ZeroNode(PythonFunctionOperator(get_file_data), _id="node1").save()
    n2 = ZeroNode(PythonFunctionOperator(get_file_data), _id="node2").save()
    n3 = OwnZeroNode(PythonFunctionOperator(get_file_data), _id="node3").save()
    bash_save = ZeroNode(BashPerPacketOperator(cmd_generator), _id="bash_save")

    return ZeroNetwork([
        ZeroPipe(ZeroNode.IN, b, _id="in-balancer"),
        ZeroPipe("balancer", "/zero/nodes/node1", _id="balancer-node1"),
        ZeroPipe("balancer", "/zero/nodes/node2", _id="balancer-node2"),
        ZeroPipe("balancer", "/zero/nodes/own/node3", _id="balancer-node3"),
        ZeroPipe("node1", bash_save, _id="node1-bash_save"),
        ZeroPipe("node2", bash_save, _id="node2-bash_save"),
        ZeroPipe("/zero/nodes/own/node3", bash_save, _id="node3-bash_save"),
        ZeroPipe(n1, ZeroNode.OUT, _id="node1-out"),
        ZeroPipe(n2, ZeroNode.OUT, _id="node2-out"),
        ZeroPipe(n3, ZeroNode.OUT, _id="node3-out"),
    ])
コード例 #11
0
def generate_network(name):
    transport = ZeroTransport(transport_connectors_factory,
                              serializer=serializer,
                              deserializer=deserializer)

    with ZeroPipe.transport_factory_context(transport):
        req_http = ZeroNode(ReqOperator(req_http_op))
        req_ftp = ZeroNode(ReqOperator(req_ftp_op))
        save = ZeroNode(PythonFunctionOperator(save_op))

        http_filter = RegexMatchFilter("^https?://.*")
        ftp_filter = RegexMatchFilter("^ftp://.*")

        return ZeroNetwork(
            [
                ZeroPipe(ZeroNode.IN, req_http, filters=[http_filter]),
                ZeroPipe(ZeroNode.IN, req_ftp, filters=[ftp_filter]),
                ZeroPipe(req_http, save),
                ZeroPipe(req_ftp, save),
            ],
            _id=name,
        )
コード例 #12
0
ファイル: l0_main.py プロジェクト: tethys-services/tethys
def get_network():
    node1 = ZeroNode(PythonFunctionOperator(generate_data), _id="node1").save()

    def f_odd(value):
        return value % 2 == 1

    def f_even(value):
        return value % 2 == 0

    odd_filter = SimpleJsonPathFilter("data.number", f_odd)
    even_filter = SimpleJsonPathFilter("data.number", f_even)

    custom_transport = ZeroTransport(
        PersistQueueConnector(TMP_FOLDER, queue_engine="file"))

    return ZeroNetwork([
        ZeroPipe(
            ZeroNode.IN,
            node1,
            _id="in-node1",
        ),
        ZeroPipe(
            "/zero/nodes/node1",
            ZeroNode.OUT,
            filters=[even_filter],
            transport=custom_transport,
            _id="even-out",
        ),
        ZeroPipe(
            node1,
            ZeroNode.OUT,
            filters=[odd_filter],
            transport=custom_transport,
            _id="odd-out",
        ),
    ])
コード例 #13
0
def get_network(name="l2_network"):
    try:
        return ZeroNetwork.load(name)
    except TethysRONotFound:
        return generate_network(name).save()
コード例 #14
0
    def test_input_pipes(self, pipes_list, input_pipes_list):
        network = ZeroNetwork()
        network.add_pipes(*pipes_list)

        assert list(network.input_pipes) == input_pipes_list
コード例 #15
0
 def test_add_pipes(self, pipes_list):
     network = ZeroNetwork()
     network.add_pipes(*pipes_list)
     assert list(network.pipes.values()) == pipes_list
コード例 #16
0
 def test_create_with_pipes(self, pipes_list):
     network = ZeroNetwork(pipes_list)
     assert list(network.pipes.values()) == pipes_list
コード例 #17
0
 def test_create_without_args(self):
     network = ZeroNetwork()
     assert len(network.pipes) == 0
コード例 #18
0
    def test_output_pipes(self, pipes_list, output_pipes_list):
        network = ZeroNetwork()
        network.add_pipes(*pipes_list)

        assert list(network.output_pipes) == output_pipes_list
コード例 #19
0
    def test_eq_network(self, pipes_list):
        network_a = ZeroNetwork(pipes_list)
        network_b = network_a.copy()

        assert id(network_a) != id(network_b)
        assert network_a == network_b