'test integer sockopts'

def test_int_sockopts(self):

    v = zmq.zmq_version_info()
    if (v < (3, 0)):
        default_hwm = 0
    else:
        default_hwm = 1000
    (p, s) = self.create_bound_pair(zmq.PUB, zmq.SUB)
    p.setsockopt(zmq.LINGER, 0)
    self.assertEqual(p.getsockopt(zmq.LINGER), 0)
    p.setsockopt(zmq.LINGER, (-1))
    self.assertEqual(p.getsockopt(zmq.LINGER), (-1))
    self.assertEqual(p.hwm, default_hwm)
    p.hwm = 11
    self.assertEqual(p.hwm, 11)
    self.assertEqual(p.getsockopt(zmq.EVENTS), zmq.POLLOUT)
    self.assertRaisesErrno(zmq.EINVAL, p.setsockopt, zmq.EVENTS, ((2 ** 7) - 1))
    self.assertEqual(p.getsockopt(zmq.TYPE), p.socket_type)
    self.assertEqual(p.getsockopt(zmq.TYPE), zmq.PUB)
    self.assertEqual(s.getsockopt(zmq.TYPE), s.socket_type)
    self.assertEqual(s.getsockopt(zmq.TYPE), zmq.SUB)
    errors = []
    backref = {}
    constants = zmq.constants
    for name in constants.__all__:
        value = getattr(constants, name)
        if isinstance(value, int):
            backref[value] = name
    for opt in zmq.constants.int_sockopts.union(zmq.constants.int64_sockopts):
        sopt = backref[opt]
        if sopt.startswith(('ROUTER', 'XPUB', 'TCP', 'FAIL', 'REQ_', 'CURVE_', 'PROBE_ROUTER', 'IPC_FILTER', 'GSSAPI', 'STREAM_', 'VMCI_BUFFER_SIZE', 'VMCI_BUFFER_MIN_SIZE', 'VMCI_BUFFER_MAX_SIZE', 'VMCI_CONNECT_TIMEOUT')):
            continue
        try:
            n = p.getsockopt(opt)
        except zmq.ZMQError as e:
            errors.append(("getsockopt(zmq.%s)    raised    '%s'." % (sopt, e)))
        else:
            if (n > (2 ** 31)):
                errors.append(('getsockopt(zmq.%s)    returned    a    ridiculous    value.    It    is    probably    the    wrong    type.' % sopt))
    if errors:
        self.fail('\n'.join(([''] + errors)))
