コード例 #1
0
    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)
コード例 #2
0
    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'
コード例 #3
0
    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
コード例 #4
0
 def round(*args, **kwargs):
     h = websockets_frame.FrameHeader(*args, **kwargs)
     h2 = websockets_frame.FrameHeader.from_file(
         tutils.treader(bytes(h)))
     assert h == h2
コード例 #5
0
 def test_serialization_too_large(self):
     h = websockets_frame.FrameHeader(payload_length=2**64 + 1, )
     with pytest.raises(ValueError):
         bytes(h)
コード例 #6
0
 def test_serialization_length(self, input, expected):
     h = websockets_frame.FrameHeader(
         opcode=Opcode.TEXT,
         payload_length=input,
     )
     assert bytes(h) == codecs.decode(expected, 'hex')
コード例 #7
0
 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")
コード例 #8
0
 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