Skip to content

Commit

Permalink
Define unit test for on_update conflation
Browse files Browse the repository at this point in the history
  • Loading branch information
agberk committed Aug 25, 2024
1 parent 1180457 commit e07b7c6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e07b7c6

Please sign in to comment.