Esempio n. 1
0
    def test_network_downstream_nodes(self):
        net = networks.Network()
        self.db.add(net)
        self.db.commit()

        node1 = models.Node(network=net)
        node2 = models.Node(network=net)
        agent1 = nodes.Agent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        source1 = nodes.Source(network=net)
        nodes.Source(network=net)

        node1.connect(whom=[node2, agent1, agent2])

        raises(TypeError, node1.connect, whom=source1)

        assert set(node1.neighbors(direction="to")) == set(
            [node2, agent1, agent2])
        assert len(node1.vectors(direction="outgoing")) == 3
        assert set(node1.neighbors(direction="to",
                                   type=nodes.Agent)) == set([agent1, agent2])

        agent1.fail()
        agent2.fail()

        raises(ValueError, node1.neighbors, direction="ghbhfgjd")
Esempio n. 2
0
    def test_network_sources(self, db_session):
        net = networks.Network()
        db_session.add(net)

        assert len(net.nodes(type=nodes.Source)) == 0

        source = nodes.Source(network=net)

        assert net.nodes(type=nodes.Source) == [source]
Esempio n. 3
0
    def test_network_sources(self):
        net = networks.Network()
        self.db.add(net)
        self.db.commit()

        assert len(net.nodes(type=nodes.Source)) == 0

        source = nodes.Source(network=net)

        assert net.nodes(type=nodes.Source) == [source]
Esempio n. 4
0
    def test_create_empty_with_source(self):
        """A sourced empty network should have nodes and an edge for each."""
        net = networks.Empty()
        self.db.add(net)
        self.db.commit()

        for i in range(10):
            agent = nodes.Agent(network=net)
            net.add_node(agent)

        source = nodes.Source(network=net)
        net.add_source(source)

        assert len(net.nodes(type=nodes.Agent)) == 10
        assert len(net.vectors()) == 10
Esempio n. 5
0
    def test_node_failure(self, db_session):
        net = networks.Network()
        db_session.add(net)

        for _ in range(5):
            nodes.Agent(network=net)
        nodes.Source(network=net)

        assert len(net.nodes(type=nodes.Agent)) == 5

        random.choice(net.nodes(type=nodes.Agent)).fail()

        assert len(net.nodes(type=nodes.Agent)) == 4
        assert len(net.nodes(type=nodes.Agent, failed="all")) == 5
        assert len(net.nodes()) == 5
        assert len(net.nodes(failed="all")) == 6
        assert len(net.nodes(failed=True)) == 1