Skip to content

Commit d965656

Browse files
committed
Adding test
1 parent d9519b0 commit d965656

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/unit/test_metrics.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,40 @@ def test_json_log_metric_handler_discharge_with_accumulate(mocker):
202202
# Accumulating metric should be reset to 0, non-accumulating should remain
203203
assert handler.metrics[accumulating_metric] == 0
204204
assert handler.metrics[non_accumulating_metric] == 7
205+
206+
207+
def test_json_log_metric_handler_discharge_with_accumulate_and_decrement(mocker):
208+
"""Test that JsonLogMetricHandler does not decrement accumulating metrics"""
209+
handler = JsonLogMetricHandler()
210+
211+
accumulating_metric = Metric("test_accumulate", accumulate=True)
212+
non_accumulating_metric = Metric("test_no_accumulate", accumulate=False)
213+
214+
handler.increment(accumulating_metric, 10)
215+
handler.decrement(accumulating_metric, 7)
216+
217+
handler.increment(non_accumulating_metric, 10)
218+
handler.decrement(non_accumulating_metric, 7)
219+
220+
# Accumulating metric should be reset to 0, non-accumulating should remain
221+
assert handler.metrics[accumulating_metric] == 10
222+
assert handler.metrics[non_accumulating_metric] == 3
223+
224+
225+
def test_console_metric_handler_discharge_with_accumulate_and_decrement(mocker):
226+
"""Test that ConsoleMetricHandler does not decrement accumulating metrics"""
227+
mock_command = mocker.Mock()
228+
handler = ConsoleMetricHandler(mock_command)
229+
230+
accumulating_metric = Metric("test_accumulate", accumulate=True)
231+
non_accumulating_metric = Metric("test_no_accumulate", accumulate=False)
232+
233+
handler.increment(accumulating_metric, 10)
234+
handler.decrement(accumulating_metric, 7)
235+
236+
handler.increment(non_accumulating_metric, 10)
237+
handler.decrement(non_accumulating_metric, 7)
238+
239+
# Accumulating metric should be reset to 0, non-accumulating should remain
240+
assert handler.metrics[accumulating_metric] == 10
241+
assert handler.metrics[non_accumulating_metric] == 3

0 commit comments

Comments
 (0)