コード例 #1
0
 def test_basic(self):
     path_policy = MagicMock(spec_set=['history_limit'])
     path_policy.history_limit = 3
     pth_str = PathStore(path_policy)
     pth_str._update_all_disjointness = MagicMock(spec_set=[])
     pth_str._update_all_delay_time = MagicMock(spec_set=[])
     pth_str.candidates = [MagicMock(spec_set=['update_fidelity'])
                           for i in range(5)]
     pth_str._update_all_fidelity()
     pth_str._update_all_disjointness.assert_called_once_with()
     pth_str._update_all_delay_time.assert_called_once_with()
     for i in range(5):
         pth_str.candidates[i].update_fidelity.assert_called_once_with(
             path_policy)
コード例 #2
0
 def _setup(self):
     inst = PathStore("path_policy")
     inst._remove_expired_segments = create_mock()
     inst._update_all_fidelity = create_mock()
     inst.candidates = []
     for i, fidelity in enumerate([0, 5, 2, 6, 3]):
         candidate = create_mock(["pcb", "fidelity", "sending"])
         candidate.pcb = "pcb%d" % i
         candidate.fidelity = fidelity
         inst.candidates.append(candidate)
     return inst
コード例 #3
0
 def test_basic(self):
     pth_str = PathStore(self.path_policy)
     pth_str.candidates = [MagicMock(spec_set=['id', 'fidelity'])
                           for i in range(5)]
     for i in range(5):
         pth_str.candidates[i].id = i
         pth_str.candidates[i].fidelity = i
     pth_str._update_all_fidelity = MagicMock(spec_set=[])
     pth_str.remove_segments([1, 2, 3])
     ntools.eq_(len(pth_str.candidates), 2)
     ntools.eq_(pth_str.candidates[0].id, 4)
     ntools.eq_(pth_str.candidates[1].id, 0)
     pth_str._update_all_fidelity.assert_called_once_with()
コード例 #4
0
 def test_remove_low_fidelity_path(self, psi):
     """
     Add a path, find that the candidate set size is too large, and remove
     the lowest-fidelity path.
     """
     pth_str = PathStore("path_policy")
     pth_str.path_policy = MagicMock(spec_set=['candidates_set_size'])
     pth_str.path_policy.candidates_set_size = 2
     pth_str.candidates = [create_mock(['fidelity']) for i in range(3)]
     pth_str.candidates[0].fidelity = 2
     pth_str.candidates[1].fidelity = 0
     pth_str.candidates[2].fidelity = 1
     remainder = [pth_str.candidates[0], pth_str.candidates[2]]
     pth_str._remove_expired_segments = create_mock()
     pth_str._update_all_fidelity = create_mock()
     pth_str._trim_candidates()
     pth_str._remove_expired_segments.assert_called_once_with()
     pth_str._update_all_fidelity.assert_called_once_with()
     ntools.eq_(pth_str.candidates, remainder)