diff --git a/.travis.yml b/.travis.yml index 8c22b32..8746ea4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,13 @@ language: python python: - 2.7 + - 3.5 - 3.6 - 3.7 - 3.8 - 3.9 + before_install: - sudo apt-get install python-dev libevent-dev - pip install Cython diff --git a/test/test_websocket.py b/test/test_websocket.py index 42ec208..29e451f 100644 --- a/test/test_websocket.py +++ b/test/test_websocket.py @@ -5,10 +5,13 @@ import struct try: + from io import BytesIO from unittest.mock import MagicMock, call, patch except ImportError: + from StringIO import StringIO as BytesIO from mock import MagicMock, call, patch + from ws4py.framing import Frame, \ OPCODE_CONTINUATION, OPCODE_TEXT, \ OPCODE_BINARY, OPCODE_CLOSE, OPCODE_PING, OPCODE_PONG @@ -180,6 +183,25 @@ def test_sending_ping(self): ws.ping("hello") m.sendall.assert_called_once_with(tm) + def test_spill_frame(self): + data = b"hello" + buf = BytesIO(data + b"spillover") + + sock = MagicMock() + sock._ssl = object() # for WebSocket._is_secure logic + sock.recv.side_effect = buf.read + sock.pending.side_effect = lambda: buf.tell() < len(buf.getvalue()) + + ws = WebSocket(sock=sock) + ws.stream = MagicMock() + + self.assertTrue(ws._is_secure) + + ws.reading_buffer_size = len(data) + ws.once() + + ws.stream.parser.send.assert_called_once_with(data) + @patch("ws4py.websocket.Heartbeat") def test_run(self, mocker):