From d31897efb80f50c2797cd6a43c579be93ae170a6 Mon Sep 17 00:00:00 2001 From: joelostblom Date: Sat, 16 May 2020 13:24:19 -0700 Subject: [PATCH] Test sorted_groupby for reverse log flag --- tests/test_utils.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index f8d47db4..84153af9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -8,6 +8,7 @@ import json import os import datetime +import operator try: from StringIO import StringIO @@ -32,6 +33,7 @@ get_start_time_for_period, make_json_writer, safe_save, + sorted_groupby, parse_tags, PY2, json_arrow_encoder, @@ -270,6 +272,32 @@ def test_build_csv_multiple_cols(): assert build_csv(data) == result +# sorted_groupby + +def test_sorted_groupby(watson): + end = arrow.utcnow() + watson.add('foo', end.shift(hours=-25), end.shift(hours=-24), ['A']) + watson.add('bar', end.shift(hours=-1), end, ['A']) + + result = list(sorted_groupby( + watson.frames, + operator.attrgetter('day'), + reverse=False)) + assert result[0][0] < result[1][0] + + +def test_sorted_groupby_reverse(watson): + end = arrow.utcnow() + watson.add('foo', end.shift(hours=-25), end.shift(hours=-24), ['A']) + watson.add('bar', end.shift(hours=-1), end, ['A']) + + result = list(sorted_groupby( + watson.frames, + operator.attrgetter('day'), + reverse=True)) + assert result[0][0] > result[1][0] + + # frames_to_csv def test_frames_to_csv_empty_data(watson):