Пример #1
0
def test_addRemoveOutputDevicePlugin():
    manager = OutputDeviceManager()
    plugin_1 = OutputDevicePlugin()
    plugin_1.setPluginId("plugin_one")

    plugin_1.start = MagicMock()
    plugin_1.stop = MagicMock()

    manager.addOutputDevicePlugin(plugin_1)
    assert manager.getOutputDevicePlugin("plugin_one") == plugin_1
    assert plugin_1.start.call_count == 1

    # adding it again shouldn't cause the start to be called again!
    manager.addOutputDevicePlugin(plugin_1)
    assert plugin_1.start.call_count == 1

    manager.removeOutputDevicePlugin("plugin_one")
    assert manager.getOutputDevicePlugin("plugin_one") is None
    assert plugin_1.start.call_count == 1

    # And removing it again shouldn't cause issues.
    manager.removeOutputDevicePlugin("plugin_two")
    assert plugin_1.start.call_count == 1

    # As the default output device plugin is an interface, the start and stop will raise exceptions.
    # but the outputdevice manager should be robust against that, so even in that case it shouldn't fail!
    plugin_2 = OutputDevicePlugin()
    plugin_2.setPluginId("plugin_two")
    manager.addOutputDevicePlugin(plugin_2)
    manager.removeOutputDevicePlugin("plugin_two")