# Path: test/simple.py
# class Base(unittest.TestCase):
#     config = CONFIG
# 
#     def setUp(self):
#         self.do_init()
#         time.sleep(START_TIMEOUT)
# 
#     def do_init(self):
#         self.proc = subprocess.Popen([ZEROGW_BINARY, '-c', self.config])
#         self.addCleanup(stop_process, self.proc)
# 
#     def http(self, host='localhost'):
#         conn = http.HTTPConnection(host, timeout=1.0)
#         conn.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
#         for i in range(100):
#             try:
#                 conn.sock.connect(HTTP_ADDR)
#             except socket.error:
#                 time.sleep(0.1)
#                 continue
#             else:
#                 break
#         else:
#             raise RuntimeError("Can't connect to zerogw")
#         return conn
# 
#     def websock(self, **kw):
#         return CheckingWebsock(self, **kw)
# 
# class TimeoutError(Exception):
#     pass


import zmq
import unittest
from http import client as http
from .simple import Base, TimeoutError


CONFIG='test/wlimit.yaml'
CHAT_FW = "ipc:///tmp/zerogw-test-chatfw"

class Wlimit(Base):
    timeout = 2  # in zmq.select units (seconds)
    config = CONFIG

    def setUp(self):
        self.zmq = zmq.Context(1)
        self.addCleanup(self.zmq.term)
        super().setUp()
        self.chatfw = self.zmq.socket(zmq.PULL)
        self.addCleanup(self.chatfw.close)

# Path: test/simple.py
# class Base(unittest.TestCase):
#     config = CONFIG
# 
#     def setUp(self):
#         self.do_init()
#         time.sleep(START_TIMEOUT)
# 
#     def do_init(self):
#         self.proc = subprocess.Popen([ZEROGW_BINARY, '-c', self.config])
#         self.addCleanup(stop_process, self.proc)
# 
#     def http(self, host='localhost'):
#         conn = http.HTTPConnection(host, timeout=1.0)
#         conn.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
#         for i in range(100):
#             try:
#                 conn.sock.connect(HTTP_ADDR)
#             except socket.error:
#                 time.sleep(0.1)
#                 continue
#             else:
#                 break
#         else:
#             raise RuntimeError("Can't connect to zerogw")
#         return conn
# 
#     def websock(self, **kw):
#         return CheckingWebsock(self, **kw)
# 
# class TimeoutError(Exception):
#     pass


# Path: test/wlimit.py
import zmq
import unittest
from http import client as http
from .simple import Base, TimeoutError



CONFIG='test/wlimit.yaml'
CHAT_FW = "ipc:///tmp/zerogw-test-chatfw"

class Wlimit(Base):
    timeout = 2  # in zmq.select units (seconds)
    config = CONFIG

    def setUp(self):
        self.zmq = zmq.Context(1)
        self.addCleanup(self.zmq.term)
        super().setUp()
        self.chatfw = self.zmq.socket(zmq.PULL)
        self.addCleanup(self.chatfw.close)

        self.chatfw.connect(CHAT_FW)