Exemple #1
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'')
        )
Exemple #2
0
def test_repr_for_text():
    msg = Message.build([Frame(Opcode.TEXT)])
    assert repr(msg) == "<message TEXT %s>" % repr(u'')
Exemple #3
0
def test_build_regular_message():
    msg = Message.build([Frame(Opcode.CONTINUATION)])
    assert isinstance(msg, Message)