From 529db3913fa723aa710b2592403c793eb000d9e7 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Wed, 3 Apr 2024 16:59:58 -0700 Subject: [PATCH] Improve assertEventOrder failure output Signed-off-by: Christophe Bedard --- tracetools_test/tracetools_test/case.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tracetools_test/tracetools_test/case.py b/tracetools_test/tracetools_test/case.py index cb6e749e..12bc252e 100644 --- a/tracetools_test/tracetools_test/case.py +++ b/tracetools_test/tracetools_test/case.py @@ -319,11 +319,16 @@ def assertEventOrder( # noqa: N802 events: List[DictEvent], ) -> None: """ - Check that the first event was generated before the second event. + Check that the events are ordered (from their timestamps). :param events: the events in the expected order """ - self.assertTrue(self.are_events_ordered(events), f'unexpected events order: {events}') + events_ordered = sorted(events, key=lambda event: get_event_timestamp(event)) + self.assertListEqual( + events, + events_ordered, + f'unexpected events order: {events}', + ) def assertNumEventsEqual( # noqa: N802 self, @@ -539,8 +544,7 @@ def are_events_ordered( :param events: the events in the expected order """ - orders = [ + return all( get_event_timestamp(events[i]) < get_event_timestamp(events[i + 1]) for i in range(len(events) - 1) - ] - return all(orders) + )