HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/anaconda3/Lib/site-packages/zmq/tests/test_ext.py
"""tests for extending pyzmq"""

import zmq


class CustomSocket(zmq.Socket):
    custom_attr: int

    def __init__(self, context, socket_type, custom_attr: int = 0):
        super().__init__(context, socket_type)
        self.custom_attr = custom_attr


class CustomContext(zmq.Context):
    extra_arg: str
    _socket_class = CustomSocket

    def __init__(self, extra_arg: str = 'x'):
        super().__init__()
        self.extra_arg = extra_arg


def test_custom_context():
    ctx = CustomContext('s')
    assert isinstance(ctx, CustomContext)

    assert ctx.extra_arg == 's'
    s = ctx.socket(zmq.PUSH, custom_attr=10)
    assert isinstance(s, CustomSocket)
    assert s.custom_attr == 10
    assert s.context is ctx
    assert s.type == zmq.PUSH
    s.close()
    ctx.term()