Skip to content

Commit

Permalink
Add tests and changelog info for fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
cgevans committed Jul 31, 2023
1 parent 5ba1bf2 commit 9834f2d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ SPDX-License-Identifier: AGPL-3.0-only

# Changelog

## Version 0.9.2

- Fix a communications bug where a packet that can cause commands to hang in certain rare situations.

## Version 0.9.1

- Minor bug fixes and dependency updates (to fix pandas errors).
Expand Down
2 changes: 1 addition & 1 deletion src/qslib/qs_is_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def data_received(self, data: bytes) -> None:
if m.end() != len(data):
raise ValueError(data, m[0])
# We have an unclosed tag opener (<) at the end of the data
logging.debug(f"Unclosed tag opener: {m[0]!r}")
log.debug(f"Unclosed tag opener: {m[0]!r}")
self.buffer.write(data[lastwrite : m.start()])
self.unclosed_quote_pos = self.buffer.tell()
self.buffer.write(m[0])
Expand Down
41 changes: 41 additions & 0 deletions tests/test_is_protocol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import asyncio
import logging

import pytest

from qslib.qs_is_protocol import QS_IS_Protocol


@pytest.fixture
def fake_connection():
q = QS_IS_Protocol.__new__(QS_IS_Protocol)
q.connection_made(None)
return q


def test_partial_quote(
fake_connection: QS_IS_Protocol,
monkeypatch: pytest.MonkeyPatch,
caplog: pytest.LogCaptureFixture,
):
def setparsed(msg):
fake_connection._parsed = msg

monkeypatch.setattr(asyncio, "create_task", lambda x: x)
monkeypatch.setattr(fake_connection, "parse_message", setparsed)

fake_connection.data_received(b"<tag>\n")
assert fake_connection.quote_stack == [b"tag"]

fake_connection.data_received(b"12345\n")

with caplog.at_level(logging.DEBUG, logger="qslib.qs_is_protocol"):
fake_connection.data_received(b"</ta")

assert "Unclosed tag opener: b'</ta'" in caplog.messages
assert fake_connection.quote_stack == [b"tag"]

fake_connection.data_received(b"g>\n")
assert fake_connection.quote_stack == []

assert fake_connection._parsed == b"<tag>\n12345\n</tag>\n"

0 comments on commit 9834f2d

Please sign in to comment.