def test_stop(bus, listener, log_tracker):
    """Test that bus stop sequence calls all listeners."""
    num = 3

    for index in range(num):
        bus.subscribe('stop', listener.get_listener('stop', index))

    bus.stop()

    # The stop method MUST call all 'stop' listeners.
    assert set(listener.responses) == set(
        msg % (i, 'stop', None) for i in range(num)
    )

    # The stop method MUST move the state to STOPPED
    assert bus.state == bus.states.STOPPED

    # The stop method MUST log its states.
    assert log_tracker.log_entries == ['Bus STOPPING', 'Bus STOPPED']
Test that bus stop sequence calls all listeners.
cherrypy/test/test_bus.py