示例#1
0
    def test_break_on_event(self):
        """
        _process_events() breaks on event_handlers that return True
        """
        block = DummyProcessBlock()
        block.events = OrderedDict([
            ("first", Event()),
            ("second", Event()),
            ("third", Event()),
        ])
        block.event_handlers = {
            "first": Mock(return_value=False),
            "second": Mock(return_value=True),
            "third": Mock(return_value=False),
        }

        for event in block.events.values():
            event.set()
        block.event.set()

        # An event was processed -> return True
        self.assertTrue(block._process_events())

        # The first and second events were processed...
        block.event_handlers["first"].method.assert_called_once()
        block.event_handlers["second"].method.assert_called_once()
        # but not the third
        block.event_handlers["third"].method.assert_not_called()
示例#2
0
 def test_process_one_event(self):
     """
     If an event is set _process_events() runs its handler
     """
     block = DummyProcessBlock()
     block.events = OrderedDict([
         ("dummy_event", Event()),
     ])
     block.event_handlers = {
         "dummy_event": Mock(return_value=False),
     }
     block.events["dummy_event"].set()
     block.event.set()
     # An event was processed -> return True
     self.assertTrue(block._process_events())
     block.event_handlers["dummy_event"].method.assert_called_once()