How to use dallinger - 10 common examples

To help you get started, we’ve selected a few dallinger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_node_connect(self, db_session):
        """Test connecting one node to another"""
        net = models.Network()
        db_session.add(net)
        db_session.commit()

        node1 = models.Node(network=net)
        node2 = models.Node(network=net)
        node3 = models.Node(network=net)
        node4 = models.Node(network=net)

        node1.connect(whom=node2)

        assert node1.neighbors(direction="to") == [node2]

        assert node2.neighbors(direction="from") == [node1]

        node2.connect(whom=[node3, node4])

        for n in node2.neighbors(direction="to"):
            assert n in [node3, node4]
        assert node3.neighbors(direction="from") == [node2]
github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_node_indegree(self, db_session):
        net = models.Network()
        self.add(db_session, net)
        node1 = models.Node(network=net)
        db_session.add(node1)
        db_session.commit()

        for i in range(5):
            assert len(node1.vectors(direction="incoming")) == i
            new_node = models.Node(network=net)
            db_session.add(new_node)
            db_session.commit()
            node1.connect(direction="from", whom=new_node)
            self.add(db_session, new_node)

        assert len(node1.vectors(direction="incoming")) == 5

        nodes = db_session.query(models.Node).all()
        node5 = [n for n in nodes if len(n.vectors(direction="incoming")) == 5][0]
        assert node5 == node1
github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_node_has_connection_to(self, db_session):
        net = models.Network()
        self.add(db_session, net)
        node1 = models.Node(network=net)
        node2 = models.Node(network=net)
        self.add(db_session, node1, node2)
        db_session.commit()

        node1.connect(whom=node2)
        self.add(db_session, node1, node2)

        assert node1.is_connected(direction="to", whom=node2)
        assert not node2.is_connected(direction="to", whom=node1)
github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_node_outdegree(self, db_session):
        net = models.Network()
        self.add(db_session, net)
        node1 = models.Node(network=net)
        db_session.add(node1)

        for i in range(5):
            assert len(node1.vectors(direction="outgoing")) == i
            new_node = models.Node(network=net)
            self.add(db_session, new_node)
            db_session.commit()
            node1.connect(whom=new_node)
            self.add(db_session, new_node)

        assert len(node1.vectors(direction="outgoing")) == 5

        nodes = db_session.query(models.Node).all()

        node5 = [n for n in nodes if len(n.vectors(direction="outgoing")) == 5][0]
        assert node5 == node1
github Dallinger / Dallinger / tests / test_sources.py View on Github external
def test_broadcast_random_binary_string_source(self, db_session):
        net = models.Network()
        self.add(db_session, net)
        source = nodes.RandomBinaryStringSource(network=net)
        agent1 = nodes.ReplicatorAgent(network=net)
        agent2 = nodes.ReplicatorAgent(network=net)
        db_session.add(agent1)
        db_session.add(agent2)
        db_session.commit()
        source.connect(whom=agent1)
        source.connect(whom=agent2)
        self.add(db_session, source, agent1, agent2)

        source.transmit(what=source.create_information())
        db_session.commit()

        agent1.receive()
        agent2.receive()
github Dallinger / Dallinger / tests / test_information.py View on Github external
def test_create_genome(self, db_session):
        net = models.Network()
        db_session.add(net)
        node = models.Node(network=net)
        info = information.Gene(origin=node)
        db_session.commit()

        assert info.type == "gene"
        assert info.contents is None
github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_node_repr(self, db_session):
        """Test the repr of a node"""
        net = models.Network()
        db_session.add(net)
        node = models.Node(network=net)
        self.add(db_session, node)

        assert repr(node).split("-") == ["Node", str(node.id), "node"]
github Dallinger / Dallinger / tests / test_sources.py View on Github external
def test_transmit_random_binary_string_source(self, db_session):
        net = models.Network()
        self.add(db_session, net)
        source = nodes.RandomBinaryStringSource(network=net)
        agent = nodes.ReplicatorAgent(network=net)
        db_session.add(source)
        db_session.add(agent)
        db_session.commit()

        source.connect(whom=agent)
        self.add(db_session, source, agent)

        source.transmit(to_whom=agent)
        db_session.commit()

        agent.receive()
        db_session.commit()
github Dallinger / Dallinger / tests / test_environments.py View on Github external
def test_create_environment_get_observed(self, db_session):
        net = models.Network()
        db_session.add(net)
        environment = nodes.Environment(network=net)
        information.State(origin=environment, contents="foo")

        agent = nodes.ReplicatorAgent(network=net)

        environment.connect(direction="to", whom=agent)
        environment.transmit(to_whom=agent)
        agent.receive()

        assert agent.infos()[0].contents == "foo"
github Dallinger / Dallinger / tests / test_models.py View on Github external
def test_transmit_raises_if_no_connection_to_destination(self, db_session):
        net1 = models.Network()
        net2 = models.Network()
        agent1 = nodes.ReplicatorAgent(network=net1)
        agent2 = nodes.ReplicatorAgent(network=net2)

        info1 = models.Info(origin=agent1, contents="foo")
        info2 = models.Info(origin=agent1, contents="bar")
        self.add(db_session, info1, info2)

        with raises(ValueError) as excinfo:
            agent1.transmit(what=None, to_whom=agent2)
            assert excinfo.match("cannot transmit to {}".format(agent2))