def test_it_invokes_the_callback_for_one_entity(self): # Given callback = Mock() fake_entity = fake("Function") async_publisher = AsyncPublisher(callback) async_publisher.start() # When async_publisher.on_entity(fake_entity) async_publisher.stop() # Then callback.assert_called_once_with(fake_entity)
def test_on_entity_returns_before_the_callback_completes(self): # Given finish = threading.Event() callback = Mock() callback.side_effect = lambda entity: finish.wait() fake_entity = fake("Function") async_publisher = AsyncPublisher(callback) async_publisher.start() # When async_publisher.on_entity(fake_entity) finish.set() # Then async_publisher.stop()
def test_it_invokes_the_callback_for_two_entities(self): # Given callback = Mock() fake_class = fake("Class_") fake_function = fake("Function") async_publisher = AsyncPublisher(callback) async_publisher.start() # When async_publisher.on_entity(fake_class) async_publisher.on_entity(fake_function) async_publisher.stop() # Then callback.assert_has_calls([call(fake_class), call(fake_function)])