Exemplo n.º 1
0
def test_decompress_broken():
    frames = [Frame(1, b'hello', fin=0), Frame(0, b' world!', fin=1)]

    def decompress(frames):
        raise ValueError('broken')

    with pytest.raises(CriticalProtocolError):
        Message.decompress_frames(frames, decompress)
Exemplo n.º 2
0
def test_build_control_messages(opcode, message_class, attrname):
    frames = [
        Frame(opcode)
    ]

    msg = Message.build(frames)

    assert isinstance(msg, message_class)
    # check if the message passes is_{type} attribute test
    assert getattr(msg, attrname) is True
    # also, check if the message doesn't pass any other is_{type} attribute
    # test
    props = filter(
        lambda prop: prop != attrname and prop.startswith('is_'),
        dir(msg)
    )

    for prop in props:
        assert getattr(msg, prop) is False

    # let's check the repr as well
    if opcode not in (Opcode.TEXT, Opcode.CLOSE):
        assert repr(msg) == "<message %s %s>" % (
            Opcode.to_str(opcode), repr(b'')
        )
Exemplo n.º 3
0
def test_constructor():
    msg = Message(Opcode.TEXT)
    assert isinstance(msg, Message)
    assert msg.opcode == Opcode.TEXT
    assert repr(msg) == '<message TEXT>'
Exemplo n.º 4
0
def test_repr_for_text():
    msg = Message.build([Frame(Opcode.TEXT)])
    assert repr(msg) == "<message TEXT %s>" % repr(u'')
Exemplo n.º 5
0
def test_build_regular_message():
    msg = Message.build([Frame(Opcode.CONTINUATION)])
    assert isinstance(msg, Message)
Exemplo n.º 6
0
def test_decompress():
    assert Message.decompress_frames('foo', lambda frames: frames) == 'foo'