From c29d1b3ce9f38bd4ddb2b85855d6b019894bd2f2 Mon Sep 17 00:00:00 2001 From: cwasicki <126617870+cwasicki@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:56:41 +0100 Subject: [PATCH] Implement close() on BatchUnrollReceiver The inherited Receiver.close() raises NotImplementedError, which pylint 4.1 also reports as an unimplemented abstract method. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com> --- RELEASE_NOTES.md | 2 ++ .../reporting/_batch_unroll_receiver.py | 5 +++++ tests/test_batch_unroll_receiver.py | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/test_batch_unroll_receiver.py diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e723f15..3b4c0a4 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -16,3 +16,5 @@ ## Bug Fixes + +* Implement `close()` on the receiver returned by the streaming methods, which raised `NotImplementedError` before. diff --git a/src/frequenz/client/reporting/_batch_unroll_receiver.py b/src/frequenz/client/reporting/_batch_unroll_receiver.py index 0994b6e..fe36d52 100644 --- a/src/frequenz/client/reporting/_batch_unroll_receiver.py +++ b/src/frequenz/client/reporting/_batch_unroll_receiver.py @@ -72,3 +72,8 @@ def consume(self) -> MetricSample: raise RuntimeError("consume called before ready") self._latest_sample = None return sample + + @override + def close(self) -> None: + """Close the underlying batch stream.""" + self._stream.close() diff --git a/tests/test_batch_unroll_receiver.py b/tests/test_batch_unroll_receiver.py new file mode 100644 index 0000000..ab80519 --- /dev/null +++ b/tests/test_batch_unroll_receiver.py @@ -0,0 +1,19 @@ +# License: MIT +# Copyright © 2026 Frequenz Energy-as-a-Service GmbH + +"""Tests for the `BatchUnrollReceiver`.""" + +from unittest.mock import MagicMock + +from frequenz.channels import Receiver + +from frequenz.client.reporting._batch_unroll_receiver import BatchUnrollReceiver + + +def test_close_closes_stream() -> None: + """Closing the receiver closes the underlying stream.""" + stream = MagicMock(spec=Receiver) + + BatchUnrollReceiver(stream).close() + + stream.close.assert_called_once_with()