def _check(self, value, expected): inst = SCIONPath() inst._ofs = create_mock(["set"]) # Call inst._set_ofs("label", value) # Tests inst._ofs.set.assert_called_once_with("label", expected)
def test_empty(self): inst = SCIONPath() inst._ofs = [] # Call inst._init_of_idxs() # Tests ntools.eq_(inst._iof_idx, 0) ntools.eq_(inst._hof_idx, 0)
def test(self, iof): inst = SCIONPath() data = create_mock(["pop"]) inst._ofs = create_mock(["set"]) # Call ntools.eq_(inst._parse_iof(data, "label"), iof.return_value) # Tests data.pop.assert_called_once_with(iof.LEN) iof.assert_called_once_with(data.pop.return_value) inst._ofs.set.assert_called_once_with("label", [iof.return_value])
def test(self, hof): inst = SCIONPath() data = create_mock(["pop"]) inst._ofs = create_mock(["set"]) hof.side_effect = ["hof0", "hof1", "hof2"] # Call inst._parse_hofs(data, "label", 3) # Tests assert_these_calls(data.pop, [call(hof.LEN)] * 3) inst._ofs.set.assert_called_once_with("label", ["hof0", "hof1", "hof2"])
def _setup(self, curr_label=SCIONPath.A_IOF, b_seg=False, c_seg=False): inst = SCIONPath() inst.set_of_idxs = create_mock() inst._iof_idx = 0 inst._hof_idx = 1 inst._ofs = create_mock([ "__len__", "count", "get_idx_by_label", "get_label_by_idx", "reverse_label", "reverse_up_flag", "swap" ]) inst._ofs.__len__.return_value = 10 inst._ofs.count.side_effect = \ lambda l: self._of_count(l, b_seg, c_seg) inst._ofs.get_label_by_idx.return_value = curr_label return inst
def test_non_peer(self): inst = SCIONPath() inst._ofs = [1] iof = create_mock(["peer"]) iof.peer = False inst.get_iof = create_mock() inst.get_iof.return_value = iof inst.inc_hof_idx = create_mock() # Call inst._init_of_idxs() # Tests ntools.eq_(inst._iof_idx, 0) ntools.eq_(inst._hof_idx, 0) inst.inc_hof_idx.assert_called_once_with()
def _check(self, up, hof_idx, expected): inst = SCIONPath() inst._iof_idx = 0 inst._hof_idx = hof_idx inst._ofs = create_mock(["get_by_idx"]) iof = create_mock(["hops", "up_flag"]) iof.hops = 5 iof.up_flag = up # Call ret = inst._get_hof_ver_normal(iof) # Tests if expected is None: ntools.eq_(ret, None) else: ntools.eq_(ret, inst._ofs.get_by_idx.return_value) inst._ofs.get_by_idx.assert_called_once_with(expected)
def _check_peer(self, xover, expected): inst = SCIONPath() inst._ofs = create_mock(["__len__", "get_by_idx"]) iof = create_mock(["peer"]) inst.get_iof = create_mock() inst.get_iof.return_value = iof hof = create_mock(["xover"]) hof.xover = xover inst._ofs.get_by_idx.return_value = hof inst.inc_hof_idx = create_mock() # Call inst._init_of_idxs() # Tests inst._ofs.get_by_idx.assert_called_once_with(1) ntools.eq_(inst._iof_idx, 0) ntools.eq_(inst._hof_idx, expected)
def _setup(self, xover=False, peer=False, shortcut=False, up_flag=True): inst = SCIONPath() inst._iof_idx = 0 inst._hof_idx = 0 iof = create_mock(["peer", "shortcut", "up_flag"]) iof.peer = peer iof.shortcut = shortcut iof.up_flag = up_flag inst.get_iof = create_mock() inst.get_iof.return_value = iof hof = create_mock(["xover"]) hof.xover = xover inst.get_hof = create_mock() inst.get_hof.return_value = hof inst._get_hof_ver_normal = create_mock() inst._ofs = create_mock(["get_by_idx"]) return inst, iof, hof
def _setup(self): inst = SCIONPath() inst._ofs = create_mock(["get_by_label"]) inst._get_as_hops = create_mock() inst._get_as_hops.return_value = 5 return inst