From e07b7c62427ee3a5e91b2f5cecd78dbc6049aedb Mon Sep 17 00:00:00 2001 From: Aaron Berk Date: Mon, 26 Aug 2024 00:12:25 +0100 Subject: [PATCH] Define unit test for on_update conflation --- tests/test_stream.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_stream.py b/tests/test_stream.py index 63633cdb..7d6575d9 100644 --- a/tests/test_stream.py +++ b/tests/test_stream.py @@ -127,6 +127,27 @@ def test_on_update_no_latency( mock_calc_latency.assert_called_with(data.get("pt")) mock_process.assert_called_with(data.get("mc"), data.get("pt")) + @mock.patch("betfairlightweight.streaming.stream.logger.warning") + def test_on_update_conflation(self, mock_warning): + self.stream.update_clk = False + self.stream._max_latency = None + self.stream._lookup = '' + + data = {"pt": 12345, "con": True} + + self.stream._listener.conflate_ms = 10000 + self.stream.on_update(data) + mock_warning.assert_not_called() + + self.stream._listener.conflate_ms = None + self.stream.on_update(data) + mock_warning.assert_called_once_with("[%s: %s]: unexpected conflation", self.stream, 123) + + self.stream._listener.conflate_ms = 0 + mock_warning.reset_mock() + self.stream.on_update(data) + mock_warning.assert_called_once_with("[%s: %s]: unexpected conflation", self.stream, 123) + def test_clear_cache(self): self.stream._caches = {1: "abc"} self.stream.clear_cache()