Exemplo n.º 1
0
 def test_send_to_non_existent_node(self):
     """
     Fail gracefully if there is nowhere to route the message
     """
     message = Message('foo', 1)
     message.route(self.ucla)
     assert message.route_nodes == None, message.route_nodes
Exemplo n.º 2
0
 def test_step_message_along_route(self):
     """
     In order to display the progress of a message on Blinkenlights etc
     we want to be able to move the message along the route a step (node/light) at a time
     updating the display as we go
     """
     message = Message('utah', 1)
     message.route(self.ucla)
     message.step()
     location = message.location()
     assert location.name == 'sri'
Exemplo n.º 3
0
    def test_add_message_to_buffer_when_full(self):
        """
        Adding a message to the buffer when it is full will fail
        Want some way of showing this so we can update the display
        accordingly - e.g. turn the LEDs red.

        Sending node can then decide to route the message a different way.
        """
        message = Message('ucla', 1)
        message.route(self.ucla)
        assert self.ucla.add_message(message) == True
        assert self.ucla.add_message(message) == False
Exemplo n.º 4
0
    def test_message_gets_sent_when_leaves_buffer(self):
        """
        When a message gets to the end of the buffer it should be sent to the
        next node on its route

        Unless this is the last node on the route...
        """

        self.ucla.add_link(Link(self.sri, 0))
        message = Message('sri', 1)
        message.route(self.ucla)
        self.sri.add_message = MagicMock()
        self.ucla.add_message(message)
        for _ in range(self.ucla.buffer_length):
            self.ucla.process()
        assert self.sri.add_message.call_count == 1
        assert self.ucla.buffer_contents(0) == [None, None, None
                                                ], self.ucla.buffer_contents(0)
Exemplo n.º 5
0
    def test_dont_go_round_in_circles(self):
        """
        If there is a route back to the origin, check we don't end up going round in circles
        """
        NODES = ['ucla', 'ucsb', 'sri', 'utah']

        LINKS = [('ucla', 'sri', 1), ('ucla', 'ucsb', 1), ('ucsb', 'sri', 1),
                 ('sri', 'utah', 1), ('utah', 'sri', 1), ('sri', 'ucsb', 1),
                 ('sri', 'ucla', 1), ('ucsb', 'ucla', 1)]

        network = {}
        for node in NODES:
            network[node] = Node(node)

        for link in LINKS:
            network[link[0]].add_link(Link(network[link[1]], link[2]))

        message = Message('utah', 1)
        message.route(network['ucla'])
        assert message.route_nodes[0] == network['utah']