Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb42a8c9 authored by Myles Watson's avatar Myles Watson
Browse files

Cert: Remove exceptions from event_asserts

Use Python string formatting in assert_true.
Check for None before printing events.
Print the last event received.

Bug: 143568835
Test: ./cert/run_cert_facade_only.sh
Change-Id: I7df6250071e767da6a4f4d740b17c050ef3f8c1a
parent 213f0559
Loading
Loading
Loading
Loading
+21 −17
Original line number Original line Diff line number Diff line
@@ -97,8 +97,7 @@ class EventAsserts(object):
                    event = current_event
                    event = current_event
            except Empty:
            except Empty:
                continue
                continue
        logging.debug("Done waiting for event, got %s" %
        logging.debug("Done waiting for an event")
                      text_format.MessageToString(event, as_one_line=True))
        asserts.assert_equal(
        asserts.assert_equal(
            event,
            event,
            None,
            None,
@@ -120,10 +119,10 @@ class EventAsserts(object):
        :return:
        :return:
        """
        """
        logging.debug("assert_event_occurs")
        logging.debug("assert_event_occurs")
        event = []
        event_list = []
        iter_count = 0
        iter_count = 0
        timeout_seconds = timeout.seconds
        timeout_seconds = timeout.seconds
        while len(event) < at_least_times and timeout_seconds > 0:
        while len(event_list) < at_least_times and timeout_seconds > 0:
            iter_count += 1
            iter_count += 1
            logging.debug("Waiting for event iteration %d" % iter_count)
            logging.debug("Waiting for event iteration %d" % iter_count)
            try:
            try:
@@ -132,15 +131,18 @@ class EventAsserts(object):
                time_elapsed = datetime.now() - time_before
                time_elapsed = datetime.now() - time_before
                timeout_seconds -= time_elapsed.seconds
                timeout_seconds -= time_elapsed.seconds
                if match_fn(current_event):
                if match_fn(current_event):
                    event.append(current_event)
                    event_list.append(current_event)
            except Empty:
            except Empty:
                continue
                continue
        logging.debug("Done waiting for event, got %s" %
        logging.debug("Done waiting for event")
                      text_format.MessageToString(event, as_one_line=True))
        if len(event_list) >= 1:
            logging.debug(
                "Done waiting for event, got %s" % text_format.MessageToString(
                    event_list[-1], as_one_line=True))
        asserts.assert_true(
        asserts.assert_true(
            len(event) == at_least_times,
            len(event_list) >= at_least_times,
            msg=("Expected at least %d events, but got %d" % at_least_times,
            msg=("Expected at least %d events, but got %d" % (at_least_times,
                 len(event)))
                                                              len(event_list))))


    def assert_event_occurs_at_most(
    def assert_event_occurs_at_most(
            self,
            self,
@@ -158,7 +160,7 @@ class EventAsserts(object):
        :return:
        :return:
        """
        """
        logging.debug("assert_event_occurs_at_most")
        logging.debug("assert_event_occurs_at_most")
        event = []
        event_list = []
        iter_count = 0
        iter_count = 0
        timeout_seconds = timeout.seconds
        timeout_seconds = timeout.seconds
        while timeout_seconds > 0:
        while timeout_seconds > 0:
@@ -170,12 +172,14 @@ class EventAsserts(object):
                time_elapsed = datetime.now() - time_before
                time_elapsed = datetime.now() - time_before
                timeout_seconds -= time_elapsed.seconds
                timeout_seconds -= time_elapsed.seconds
                if match_fn(current_event):
                if match_fn(current_event):
                    event.append(current_event)
                    event_list.append(current_event)
            except Empty:
            except Empty:
                continue
                continue
        logging.debug("Done waiting for event, got %s" %
        if len(event_list) >= 1:
                      text_format.MessageToString(event, as_one_line=True))
            logging.debug(
                "Done waiting for event, got %s" % text_format.MessageToString(
                    event_list[-1], as_one_line=True))
        asserts.assert_true(
        asserts.assert_true(
            len(event) <= at_most_times,
            len(event_list) <= at_most_times,
            msg=("Expected at most %d events, but got %d" % at_most_times,
            msg=("Expected at most %d events, but got %d" % (at_most_times,
                 len(event)))
                                                             len(event_list))))