test_pair.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (C) PyZMQ Developers
  2. # Distributed under the terms of the Modified BSD License.
  3. import zmq
  4. from zmq.tests import BaseZMQTestCase, have_gevent, GreenTest
  5. x = b' '
  6. class TestPair(BaseZMQTestCase):
  7. def test_basic(self):
  8. s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
  9. msg1 = b'message1'
  10. msg2 = self.ping_pong(s1, s2, msg1)
  11. self.assertEqual(msg1, msg2)
  12. def test_multiple(self):
  13. s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
  14. for i in range(10):
  15. msg = i*x
  16. s1.send(msg)
  17. for i in range(10):
  18. msg = i*x
  19. s2.send(msg)
  20. for i in range(10):
  21. msg = s1.recv()
  22. self.assertEqual(msg, i*x)
  23. for i in range(10):
  24. msg = s2.recv()
  25. self.assertEqual(msg, i*x)
  26. def test_json(self):
  27. s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
  28. o = dict(a=10,b=list(range(10)))
  29. o2 = self.ping_pong_json(s1, s2, o)
  30. def test_pyobj(self):
  31. s1, s2 = self.create_bound_pair(zmq.PAIR, zmq.PAIR)
  32. o = dict(a=10,b=range(10))
  33. o2 = self.ping_pong_pyobj(s1, s2, o)
  34. if have_gevent:
  35. class TestReqRepGreen(GreenTest, TestPair):
  36. pass