# Path: tests/base.py
# class Test(unittest.TestCase):
#     test_timeout = 1
# 
#     def setUp(self):
#         import zorro
#         from zorro import zmq
#         self.z = zorro
#         self.hub = self.z.Hub()
#         self.thread = threading.Thread(target=self.hub.run)
# 
#     def tearDown(self):
#         if not self.hub.stopping:
#             self.hub.stop()
#         self.thread.join(self.test_timeout)
#         if self.thread.is_alive():
#             try:
#                 if not getattr(self, 'should_timeout', False):
#                     raise AssertionError("test timed out")
#             finally:
#                 self.hub.crash()
#                 self.thread.join()
#         for key in list(sys.modules.keys()):
#             if key == 'zorro' or key.startswith('zorro.'):
#                 del sys.modules[key]
# 
# def interactive(zfun):
#     def wrapper(fun):
#         @wraps(fun)
#         def wrapping(self, *a, **kw):
#             self.hub.add_task(partial(zfun, self, *a, **kw))
#             self.thread.start()
#             fun(self, *a, **kw)
#         return wrapping
#     return wrapper
# 
# def passive(zfun):
#     @wraps(zfun)
#     def wrapping(self, *a, **kw):
#         exc = []
#         def catch():
#             try:
#                 zfun(self, *a, **kw)
#             except BaseException as e:
#                 exc.append(e)
#         self.hub.add_task(catch)
#         self.thread.start()
#         try:
#             self.thread.join(self.test_timeout)
#         finally:
#             if exc:
#                 raise exc[0]
#     return wrapping


import time
import pickle
import zmq
        import zorro.pool
    import unittest
from .base import Test, interactive, passive
        sock.bind('ipc:///tmp/zorro-test-zmq')
        sock.send_multipart([b"a"])
        self.assertEqual(sock.recv_multipart(), [b"hello"])
        sock.send_multipart([b"b"])
        self.assertEqual(sock.recv_multipart(), [b"world"])

    def make_request(self):
        sock = self.z.zmq.req_socket()
        sock.connect('tcp://127.0.0.1:9999')
        self.assertEqual(sock.request([b"hello", b"world"]).get(),
            [b"world", b"hello"])
        self.assertEqual(sock.request([b"abra", b"kadabra"]).get(),
            [b"kadabra", b"abra"])

    @interactive(make_request)
    def test_req(self):
        ctx = zmq.Context(1)
        sock = ctx.socket(zmq.REP)
        sock.bind('tcp://127.0.0.1:9999')
        data = sock.recv_multipart()
        sock.send_multipart(list(reversed(data)))
        data = sock.recv_multipart()
        sock.send_multipart(list(reversed(data)))

    def subscriber(self, *words):
        if len(words) < 5:
            self.pub.publish('real', *words)
        else:
            self.pub2.publish(repr(words))


# Path: tests/base.py
# class Test(unittest.TestCase):
#     test_timeout = 1
# 
#     def setUp(self):
#         import zorro
#         from zorro import zmq
#         self.z = zorro
#         self.hub = self.z.Hub()
#         self.thread = threading.Thread(target=self.hub.run)
# 
#     def tearDown(self):
#         if not self.hub.stopping:
#             self.hub.stop()
#         self.thread.join(self.test_timeout)
#         if self.thread.is_alive():
#             try:
#                 if not getattr(self, 'should_timeout', False):
#                     raise AssertionError("test timed out")
#             finally:
#                 self.hub.crash()
#                 self.thread.join()
#         for key in list(sys.modules.keys()):
#             if key == 'zorro' or key.startswith('zorro.'):
#                 del sys.modules[key]
# 
# def interactive(zfun):
#     def wrapper(fun):
#         @wraps(fun)
#         def wrapping(self, *a, **kw):
#             self.hub.add_task(partial(zfun, self, *a, **kw))
#             self.thread.start()
#             fun(self, *a, **kw)
#         return wrapping
#     return wrapper
# 
# def passive(zfun):
#     @wraps(zfun)
#     def wrapping(self, *a, **kw):
#         exc = []
#         def catch():
#             try:
#                 zfun(self, *a, **kw)
#             except BaseException as e:
#                 exc.append(e)
#         self.hub.add_task(catch)
#         self.thread.start()
#         try:
#             self.thread.join(self.test_timeout)
#         finally:
#             if exc:
#                 raise exc[0]
#     return wrapping


# Path: tests/test_zmq.py
import time
import pickle
import zmq
        import zorro.pool
    import unittest
from .base import Test, interactive, passive

        sock.bind('ipc:///tmp/zorro-test-zmq')
        sock.send_multipart([b"a"])
        self.assertEqual(sock.recv_multipart(), [b"hello"])
        sock.send_multipart([b"b"])
        self.assertEqual(sock.recv_multipart(), [b"world"])

    def make_request(self):
        sock = self.z.zmq.req_socket()
        sock.connect('tcp://127.0.0.1:9999')
        self.assertEqual(sock.request([b"hello", b"world"]).get(),
            [b"world", b"hello"])
        self.assertEqual(sock.request([b"abra", b"kadabra"]).get(),
            [b"kadabra", b"abra"])

    @interactive(make_request)
    def test_req(self):
        ctx = zmq.Context(1)
        sock = ctx.socket(zmq.REP)
        sock.bind('tcp://127.0.0.1:9999')
        data = sock.recv_multipart()
        sock.send_multipart(list(reversed(data)))
        data = sock.recv_multipart()
        sock.send_multipart(list(reversed(data)))

    def subscriber(self, *words):
        if len(words) < 5:
            self.pub.publish('real', *words)
        else:
            self.pub2.publish(repr(words))


    @passive