def test_basic(self, time_): path_policy = MagicMock(spec_set=['history_limit']) path_policy.history_limit = 3 pth_str = PathStore(path_policy) pth_str.disjointness = {0: math.e, 1: math.e**2} pth_str.last_dj_update = 22 time_.return_value = 23 pth_str._update_disjointness_db() ntools.eq_(pth_str.last_dj_update, time_.return_value) ntools.assert_almost_equal(pth_str.disjointness[0], 1.0) ntools.assert_almost_equal(pth_str.disjointness[1], math.e)
def test(self): inst = PathStore(create_mock_full({'history_limit': 3})) numCandidates = 5 pathLength = 5 inst.candidates = [] inst.disjointness = {} for i in range(numCandidates): id_ = i * (2 * pathLength + 1) asms = [] for j in range(pathLength): isdas = 9, id_ + j + 1 hof = create_mock_full({'egress_if': isdas[1] + pathLength}) pcbm = create_mock_full({'hof()': hof}) asms.append( create_mock_full({ "isd_as()": isdas, "pcbm()": pcbm })) inst.disjointness[isdas[1]] = 1.0 inst.disjointness[hof.egress_if] = 1.0 pcb = create_mock_full({"iter_asms()": asms}) record = create_mock_full({ 'pcb': pcb, 'disjointness': 0, 'id': id_ }) inst.disjointness[id_] = 1.0 inst.candidates.append(record) inst._update_disjointness_db = create_mock() inst._update_all_disjointness() for i in range(numCandidates): ntools.assert_almost_equal(inst.candidates[i].disjointness, 1.0)