예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
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])
예제 #4
0
 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"])
예제 #5
0
 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
예제 #6
0
 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()
예제 #7
0
 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)
예제 #8
0
 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)
예제 #9
0
 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
예제 #10
0
 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