def test_human_readable(self): f = websockets_frame.FrameHeader(masking_key=b"test", fin=True, payload_length=10) assert repr(f) f = websockets_frame.FrameHeader() assert repr(f)
def test_equality(self): h = websockets_frame.FrameHeader(mask=True, masking_key=b'1234') h2 = websockets_frame.FrameHeader(mask=True, masking_key=b'1234') assert h == h2 h = websockets_frame.FrameHeader(fin=True) h2 = websockets_frame.FrameHeader(fin=False) assert h != h2 assert h != 'foobar'
def test_automask(self): f = websockets_frame.FrameHeader(mask=True) assert f.masking_key f = websockets_frame.FrameHeader(masking_key=b"foob") assert f.mask f = websockets_frame.FrameHeader(masking_key=b"foob", mask=0) assert not f.mask assert not f.masking_key
def round(*args, **kwargs): h = websockets_frame.FrameHeader(*args, **kwargs) h2 = websockets_frame.FrameHeader.from_file( tutils.treader(bytes(h))) assert h == h2
def test_serialization_too_large(self): h = websockets_frame.FrameHeader(payload_length=2**64 + 1, ) with pytest.raises(ValueError): bytes(h)
def test_serialization_length(self, input, expected): h = websockets_frame.FrameHeader( opcode=Opcode.TEXT, payload_length=input, ) assert bytes(h) == codecs.decode(expected, 'hex')
def test_violations(self): with pytest.raises(Exception, match="opcode"): websockets_frame.FrameHeader(opcode=17) with pytest.raises(Exception, match="Masking key"): websockets_frame.FrameHeader(masking_key=b"x")
def test_funky(self): f = websockets_frame.FrameHeader(masking_key=b"test", mask=False) raw = bytes(f) f2 = websockets_frame.FrameHeader.from_file(tutils.treader(raw)) assert not f2.mask