Example #1
0
 def test(self, init):
     inst = SocketMgr()
     inst._sel = create_mock(["select"])
     events = []
     for i in range(3):
         key = create_mock(["data"])
         key.data = ("sock%d" % i, "callback%d" % i)
         events.append((key, None))
     inst._sel.select.return_value = events
     # Call
     for i, (sock, callback) in enumerate(inst.select_(timeout="timeout")):
         ntools.eq_((sock, callback), ("sock%d" % i, "callback%d" % i))
     # Tests
     inst._sel.select.assert_called_once_with(timeout="timeout")
Example #2
0
 def test(self, init):
     inst = SocketMgr()
     inst._sel = create_mock(["close", "get_map"])
     inst.remove = create_mock()
     map_ = {}
     for i in range(3):
         entry = create_mock(["data"])
         entry.data = create_mock(["close"]), create_mock([])
         map_[i] = entry
     inst._sel.get_map.return_value = map_
     # Call
     inst.close()
     # Tests
     inst._sel.get_map.assert_called_once_with()
     for entry in map_.values():
         inst.remove.assert_any_call(entry.data[0])
         entry.data[0].close.assert_called_once_with()
     ntools.eq_(inst.remove.call_count, 3)
     inst._sel.close.assert_called_once_with()