Example #1
0
 def test_basic_receive(self):
   i = IOWorker()
   self.data = None
   def d(worker):
     self.data = worker.peek_receive_buf()
   i.set_receive_handler(d)
   i.push_receive_data("bar")
   self.assertEqual(self.data, "bar")
   # d does not consume the data
   i.push_receive_data("hepp")
   self.assertEqual(self.data, "barhepp")
Example #2
0
 def test_receive_consume(self):
   i = IOWorker()
   self.data = None
   def consume(worker):
     self.data = worker.peek_receive_buf()
     worker.consume_receive_buf(len(self.data))
   i.set_receive_handler(consume)
   i.push_receive_data("bar")
   self.assertEqual(self.data, "bar")
   # data has been consumed
   i.push_receive_data("hepp")
   self.assertEqual(self.data, "hepp")