def test_run(self):
        runs = []
        event = mock.MagicMock(event_type=EVENT_STATE_CHANGED,
                               data={'entity_id': 'entity',
                                     'new_state': mock.MagicMock()})

        def fake_get():
            if len(runs) >= 2:
                return self.gf._quit_object
            elif runs:
                runs.append(1)
                return mock.MagicMock(event_type='somethingelse',
                                      data={'new_event': None})
            else:
                runs.append(1)
                return event

        with mock.patch.object(self.gf, '_queue') as mock_queue:
            with mock.patch.object(self.gf, '_report_attributes') as mock_r:
                mock_queue.get.side_effect = fake_get
                self.gf.run()
                # Twice for two events, once for the stop
                self.assertEqual(3, mock_queue.task_done.call_count)
                mock_r.assert_called_once_with(
                    'entity',
                    event.data['new_state'])
Test the running.
dataset/ETHPy150Open home-assistant/home-assistant/tests/components/test_graphite.py/TestGraphite.test_run