def test_path_before_last():

    path = Path(['a1', 'a2', 'a3'])
    assert 'a2' == path.before_last()

    path = Path(['a1'])
    with pytest.raises(IndexError):
        path.before_last()

    path = Path([])
    with pytest.raises(IndexError):
        path.before_last()
Esempio n. 2
0
 def _send_answer(self, budget: float, spent: float, rq_path: Path,
                  paths: PathsTable, visited: List[AgentName],
                  comp_def: ComputationDef, footprint: float,
                  replica_count: int, hosts: List[AgentName]):
     assert rq_path.last() == self.agt_name
     target_agt = rq_path.before_last()
     cost_to_target = self.route(target_agt)
     budget += cost_to_target
     spent -= cost_to_target
     self.logger.debug(
         'sending replica answer from %s to %s for %s %s'
         '( %s %s %s )', self.name, target_agt, rq_path, comp_def.name,
         budget, spent, cost_to_target)
     self.post_msg(
         replication_computation_name(target_agt),
         UCSReplicateMessage('replicate_answer', budget, spent, rq_path,
                             paths, visited, comp_def, footprint,
                             replica_count, hosts), MSG_REPLICATION)