Skip to content

Commit

Permalink
IncrementalDeserializeError.remaining_data is no longer reset (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
francis-clairicia authored Nov 23, 2023
1 parent b5d0fb5 commit a0eefef
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/easynetwork/lowlevel/_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ def __next__(self) -> _ReceivedPacketT:
packet, remaining = exc.value
remaining = _ensure_bytes(remaining)
except StreamProtocolParseError as exc:
remaining, exc.remaining_data = exc.remaining_data, b""
remaining = _ensure_bytes(remaining)
self.__b = remaining
self.__b = _ensure_bytes(exc.remaining_data)
raise
except Exception as exc:
raise RuntimeError("protocol.build_packet_from_chunks() crashed") from exc
Expand Down
3 changes: 1 addition & 2 deletions src/easynetwork/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ def build_packet_from_chunks(self) -> Generator[None, bytes, tuple[_ReceivedPack
try:
packet, remaining_data = yield from self.__serializer.incremental_deserialize()
except IncrementalDeserializeError as exc:
remaining_data, exc.remaining_data = exc.remaining_data, b""
raise StreamProtocolParseError(remaining_data, exc) from exc
raise StreamProtocolParseError(exc.remaining_data, exc) from exc
except DeserializeError as exc:
raise RuntimeError("DeserializeError raised instead of IncrementalDeserializeError") from exc

Expand Down
1 change: 1 addition & 0 deletions tests/unit_test/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def test____build_packet_from_chunks____deserialize_error(
mock_convert_func.assert_not_called()
assert isinstance(exception.error, IncrementalDeserializeError)
assert exception.remaining_data is mocker.sentinel.chunk
assert exception.error.remaining_data is mocker.sentinel.chunk
assert isinstance(exception.__cause__, IncrementalDeserializeError)

def test____build_packet_from_chunks____wrong_deserialize_error(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_test/test_tools/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def side_effect() -> Generator[None, bytes, tuple[Any, bytes]]:
# Assert
mock_build_packet_from_chunks_func.assert_called_once_with()
assert consumer.get_buffer() == b"World"
assert exception.remaining_data == b""
assert exception.remaining_data == b"World"

def test____next____generator_did_not_yield(
self,
Expand Down

0 comments on commit a0eefef

Please sign in to comment.