def setUp(self): self.tempdir = mkdtemp() self.pm = PluginManager(folders=[self.tempdir]) self.confirmed = False self.handler = SongsMenuPluginHandler(self._confirmer, self._confirmer) self.pm.register_handler(self.handler) self.pm.rescan() self.assertEquals(self.pm.plugins, []) self.library = SongLibrary('foo')
def setUp(self): self.tempdir = mkdtemp() self.pm = PluginManager(folders=[self.tempdir]) self.lib = SongLibrarian() self.player = player.init_player("nullbe", self.lib) self.handler = EventPluginHandler( librarian=self.lib, player=self.player) self.pm.register_handler(self.handler) self.pm.rescan() self.assertEquals(self.pm.plugins, [])
def test_show_uri_with_existing_window(self): PluginManager.instance = PluginManager() # Force an instance win = PluginWindow() qltk.show_uri("foo", "quodlibet:///prefs/plugins/Squeezebox Output") # TODO: proper assertions, etc win.destroy()
def setUp(self): self.tempdir = mkdtemp() self.pm = PluginManager(folders=[self.tempdir]) self.handler = SongsMenuPluginHandler() self.pm.register_handler(self.handler) self.pm.rescan() self.assertEquals(self.pm.plugins, [])
def setUp(self): self.tempdir = mkdtemp() self.pm = PluginManager(folders=[self.tempdir]) self.confirmed = False self.mock_browser = self.MockBrowser() self.handler = PlaylistPluginHandler(self._confirmer) self.pm.register_handler(self.handler) self.pm.rescan() self.assertEquals(self.pm.plugins, []) self.library = SongLibrary("foo")
class TSongsMenuPlugins(TestCase): def _confirmer(self, *args): self.confirmed = True def setUp(self): self.tempdir = mkdtemp() self.pm = PluginManager(folders=[self.tempdir]) self.confirmed = False self.handler = SongsMenuPluginHandler(self._confirmer, self._confirmer) self.pm.register_handler(self.handler) self.pm.rescan() self.assertEquals(self.pm.plugins, []) self.library = SongLibrary('foo') def tearDown(self): self.library.destroy() self.pm.quit() for f in os.listdir(self.tempdir): os.remove(os.path.join(self.tempdir, f)) os.rmdir(self.tempdir) def create_plugin(self, id='', name='', desc='', icon='', funcs=None, mod=False): fd, fn = mkstemp(suffix='.py', text=True, dir=self.tempdir) file = os.fdopen(fd, 'w') if mod: indent = '' else: file.write( "from quodlibet.plugins.songsmenu import SongsMenuPlugin\n") file.write("class %s(SongsMenuPlugin):\n" % name) indent = ' ' file.write("%spass\n" % indent) if name: file.write("%sPLUGIN_ID = %r\n" % (indent, name)) if name: file.write("%sPLUGIN_NAME = %r\n" % (indent, name)) if desc: file.write("%sPLUGIN_DESC = %r\n" % (indent, desc)) if icon: file.write("%sPLUGIN_ICON = %r\n" % (indent, icon)) for f in (funcs or []): if f in ["__init__"]: file.write("%sdef %s(self, *args): super(%s, self).__init__(" "*args); raise Exception(\"as expected\")\n" % (indent, f, name)) else: file.write("%sdef %s(*args): return args\n" % (indent, f)) file.flush() file.close() def test_empty_has_no_plugins(self): self.pm.rescan() self.assertEquals(self.pm.plugins, []) def test_name_and_desc_plus_func_is_one(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) def test_additional_functions_still_only_one(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song', 'plugin_songs']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) def test_two_plugins_are_two(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song']) self.create_plugin(name='Name2', desc='Desc2', funcs=['plugin_albums']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 2) def test_disables_plugin(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song']) self.pm.rescan() self.failIf(self.pm.enabled(self.pm.plugins[0])) def test_enabledisable_plugin(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song']) self.pm.rescan() plug = self.pm.plugins[0] self.pm.enable(plug, True) self.failUnless(self.pm.enabled(plug)) self.pm.enable(plug, False) self.failIf(self.pm.enabled(plug)) def test_ignores_broken_plugin(self): self.create_plugin(name="Broken", desc="Desc", funcs=["__init__", "plugin_song"]) self.pm.rescan() plug = self.pm.plugins[0] self.pm.enable(plug, True) with capture_output(): menu = self.handler.Menu(None, [AudioFile()]) self.failIf(menu and menu.get_children()) def test_Menu(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song']) self.handler.Menu(None, [AudioFile()]) def test_handling_songs_without_confirmation(self): plugin = Plugin(FakeSongsMenuPlugin) self.handler.plugin_enable(plugin) MAX = FakeSongsMenuPlugin.MAX_INVOCATIONS songs = [AudioFile({'~filename': "/tmp/%s" % x, 'artist': 'foo'}) for x in range(MAX)] self.handler.handle(plugin.id, self.library, None, songs) self.failIf(self.confirmed, ("Wasn't expecting a confirmation for %d" " invocations" % len(songs))) def test_handling_lots_of_songs_with_confirmation(self): plugin = Plugin(FakeSongsMenuPlugin) self.handler.plugin_enable(plugin) MAX = FakeSongsMenuPlugin.MAX_INVOCATIONS songs = [AudioFile({'~filename': "/tmp/%s" % x, 'artist': 'foo'}) for x in range(MAX + 1)] self.handler.handle(plugin.id, self.library, None, songs) self.failUnless(self.confirmed, ("Should have confirmed %d invocations (Max=%d)." % (len(songs), MAX)))
class TPlaylistPlugins(TestCase): class MockBrowser(Browser): def __init__(self): super(TPlaylistPlugins.MockBrowser, self).__init__() self.activated = False def activate(self): self.activated = True def get_toplevel(self): return self def is_toplevel(self): return True def _confirmer(self, *args): self.confirmed = True def setUp(self): self.tempdir = mkdtemp() self.pm = PluginManager(folders=[self.tempdir]) self.confirmed = False self.mock_browser = self.MockBrowser() self.handler = PlaylistPluginHandler(self._confirmer) self.pm.register_handler(self.handler) self.pm.rescan() self.assertEquals(self.pm.plugins, []) self.library = SongLibrary('foo') def tearDown(self): self.library.destroy() self.pm.quit() for f in os.listdir(self.tempdir): os.remove(os.path.join(self.tempdir, f)) os.rmdir(self.tempdir) def create_plugin(self, id='', name='', desc='', icon='', funcs=None, mod=False): fd, fn = mkstemp(suffix='.py', text=True, dir=self.tempdir) file = os.fdopen(fd, 'w') if mod: indent = '' else: file.write( "from quodlibet.plugins.playlist import PlaylistPlugin\n") file.write("class %s(PlaylistPlugin):\n" % name) indent = ' ' file.write("%spass\n" % indent) if name: file.write("%sPLUGIN_ID = %r\n" % (indent, name)) if name: file.write("%sPLUGIN_NAME = %r\n" % (indent, name)) if desc: file.write("%sPLUGIN_DESC = %r\n" % (indent, desc)) if icon: file.write("%sPLUGIN_ICON = %r\n" % (indent, icon)) for f in (funcs or []): if f in ["__init__"]: file.write("%sdef %s(self, *args): super(%s, self).__init__(" "*args); raise Exception(\"as expected.\")\n" % (indent, f, name)) else: file.write("%sdef %s(*args): return args\n" % (indent, f)) file.flush() file.close() def test_empty_has_no_plugins(self): self.pm.rescan() self.assertEquals(self.pm.plugins, []) def test_name_and_desc_plus_func_is_one(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_playlist']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) def test_additional_functions_still_only_one(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_playlist', 'plugin_playlists']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) def test_two_plugins_are_two(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_playlist']) self.create_plugin(name='Name2', desc='Desc2', funcs=['plugin_albums']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 2) def test_disables_plugin(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_playlist']) self.pm.rescan() self.failIf(self.pm.enabled(self.pm.plugins[0])) def test_enabledisable_plugin(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_playlist']) self.pm.rescan() plug = self.pm.plugins[0] self.pm.enable(plug, True) self.failUnless(self.pm.enabled(plug)) self.pm.enable(plug, False) self.failIf(self.pm.enabled(plug)) def test_ignores_broken_plugin(self): self.create_plugin(name="Broken", desc="Desc", funcs=["__init__", "plugin_playlist"]) self.pm.rescan() plug = self.pm.plugins[0] self.pm.enable(plug, True) menu = Gtk.Menu() with capture_output(): self.handler.populate_menu(menu, None, self.mock_browser, [TEST_PLAYLIST]) self.failUnlessEqual(len(menu.get_children()), 0, msg="Shouldn't have enabled a broken plugin") def test_populate_menu(self): plugin = Plugin(FakePlaylistPlugin) self.handler.plugin_enable(plugin) menu = Gtk.Menu() self.handler.populate_menu(menu, None, self.mock_browser, [TEST_PLAYLIST]) # Don't forget the separator num = len(menu.get_children()) - 1 self.failUnlessEqual(num, 1, msg="Need 1 plugin not %d" % num) def test_handling_playlists_without_confirmation(self): plugin = Plugin(FakePlaylistPlugin) self.handler.plugin_enable(plugin) playlists = generate_playlists(MAX_PLAYLISTS) self.handler.handle(plugin.id, self.library, self.mock_browser, playlists) self.failUnless("Didn't execute plugin", FakePlaylistPlugin.total > 0) self.failIf(self.confirmed, ("Wasn't expecting a confirmation for %d" " invocations" % len(playlists))) def test_handling_lots_of_songs_with_confirmation(self): plugin = Plugin(FakePlaylistPlugin) self.handler.plugin_enable(plugin) playlists = generate_playlists(MAX_PLAYLISTS + 1) self.handler.handle(plugin.id, self.library, self.mock_browser, playlists) self.failUnless(self.confirmed, ("Should have confirmed %d invocations (Max=%d)." % (len(playlists), MAX_PLAYLISTS)))
class TEventPlugins(TestCase): def setUp(self): self.tempdir = mkdtemp() self.pm = PluginManager(folders=[self.tempdir]) self.lib = SongLibrarian() self.player = player.init_player("nullbe", self.lib) self.handler = EventPluginHandler( librarian=self.lib, player=self.player) self.pm.register_handler(self.handler) self.pm.rescan() self.assertEquals(self.pm.plugins, []) def tearDown(self): self.pm.quit() shutil.rmtree(self.tempdir) def create_plugin(self, name='', funcs=None): fd, fn = mkstemp(suffix='.py', text=True, dir=self.tempdir) file = os.fdopen(fd, 'w') file.write("from quodlibet.plugins.events import EventPlugin\n") file.write("log = []\n") file.write("class %s(EventPlugin):\n" % name) indent = ' ' file.write("%spass\n" % indent) if name: file.write("%sPLUGIN_ID = %r\n" % (indent, name)) file.write("%sPLUGIN_NAME = %r\n" % (indent, name)) for f in (funcs or []): file.write("%sdef %s(s, *args): log.append((%r, args))\n" % (indent, f, f)) file.flush() file.close() def _get_calls(self, plugin): mod = sys.modules[plugin.cls.__module__] return mod.log def test_found(self): self.create_plugin(name='Name') self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) def test_player_paused(self): self.create_plugin(name='Name', funcs=["plugin_on_paused"]) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) plugin = self.pm.plugins[0] self.pm.enable(plugin, True) self.player.emit("paused") self.failUnlessEqual([("plugin_on_paused", tuple())], self._get_calls(plugin)) def test_lib_changed(self): self.create_plugin(name='Name', funcs=["plugin_on_changed"]) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) plugin = self.pm.plugins[0] self.pm.enable(plugin, True) self.lib.emit("changed", [None]) self.failUnlessEqual([("plugin_on_changed", ([None],))], self._get_calls(plugin))
class TPlaylistPlugins(TestCase): class MockBrowser(Browser): def __init__(self): super(TPlaylistPlugins.MockBrowser, self).__init__() self.activated = False def activate(self): self.activated = True def get_toplevel(self): return self def is_toplevel(self): return True def _confirmer(self, *args): self.confirmed = True def setUp(self): self.tempdir = mkdtemp() self.pm = PluginManager(folders=[self.tempdir]) self.confirmed = False self.mock_browser = self.MockBrowser() self.handler = PlaylistPluginHandler(self._confirmer) self.pm.register_handler(self.handler) self.pm.rescan() self.assertEquals(self.pm.plugins, []) self.library = SongLibrary('foo') def tearDown(self): self.library.destroy() self.pm.quit() shutil.rmtree(self.tempdir) def create_plugin(self, id='', name='', desc='', icon='', funcs=None, mod=False): fd, fn = mkstemp(suffix='.py', text=True, dir=self.tempdir) file = os.fdopen(fd, 'w') if mod: indent = '' else: file.write( "from quodlibet.plugins.playlist import PlaylistPlugin\n") file.write("class %s(PlaylistPlugin):\n" % name) indent = ' ' file.write("%spass\n" % indent) if name: file.write("%sPLUGIN_ID = %r\n" % (indent, name)) if name: file.write("%sPLUGIN_NAME = %r\n" % (indent, name)) if desc: file.write("%sPLUGIN_DESC = %r\n" % (indent, desc)) if icon: file.write("%sPLUGIN_ICON = %r\n" % (indent, icon)) for f in (funcs or []): if f in ["__init__"]: file.write("%sdef %s(self, *args): super(%s, self).__init__(" "*args); raise Exception(\"as expected.\")\n" % (indent, f, name)) else: file.write("%sdef %s(*args): return args\n" % (indent, f)) file.flush() file.close() def test_empty_has_no_plugins(self): self.pm.rescan() self.assertEquals(self.pm.plugins, []) def test_name_and_desc_plus_func_is_one(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_playlist']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) def test_additional_functions_still_only_one(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_playlist', 'plugin_playlists']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) def test_two_plugins_are_two(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_playlist']) self.create_plugin(name='Name2', desc='Desc2', funcs=['plugin_albums']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 2) def test_disables_plugin(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_playlist']) self.pm.rescan() self.failIf(self.pm.enabled(self.pm.plugins[0])) def test_enabledisable_plugin(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_playlist']) self.pm.rescan() plug = self.pm.plugins[0] self.pm.enable(plug, True) self.failUnless(self.pm.enabled(plug)) self.pm.enable(plug, False) self.failIf(self.pm.enabled(plug)) def test_ignores_broken_plugin(self): self.create_plugin(name="Broken", desc="Desc", funcs=["__init__", "plugin_playlist"]) self.pm.rescan() plug = self.pm.plugins[0] self.pm.enable(plug, True) menu = Gtk.Menu() with capture_output(): self.handler.populate_menu(menu, None, self.mock_browser, [TEST_PLAYLIST]) self.failUnlessEqual(len(menu.get_children()), 0, msg="Shouldn't have enabled a broken plugin") def test_populate_menu(self): plugin = Plugin(FakePlaylistPlugin) self.handler.plugin_enable(plugin) menu = Gtk.Menu() self.handler.populate_menu(menu, None, self.mock_browser, [TEST_PLAYLIST]) # Don't forget the separator num = len(menu.get_children()) - 1 self.failUnlessEqual(num, 1, msg="Need 1 plugin not %d" % num) def test_handling_playlists_without_confirmation(self): plugin = Plugin(FakePlaylistPlugin) self.handler.plugin_enable(plugin) playlists = generate_playlists(MAX_PLAYLISTS) self.handler.handle(plugin.id, self.library, self.mock_browser, playlists) self.failUnless("Didn't execute plugin", FakePlaylistPlugin.total > 0) self.failIf(self.confirmed, ("Wasn't expecting a confirmation for %d" " invocations" % len(playlists))) def test_handling_lots_of_songs_with_confirmation(self): plugin = Plugin(FakePlaylistPlugin) self.handler.plugin_enable(plugin) playlists = generate_playlists(MAX_PLAYLISTS + 1) self.handler.handle(plugin.id, self.library, self.mock_browser, playlists) self.failUnless(self.confirmed, ("Should have confirmed %d invocations (Max=%d)." % (len(playlists), MAX_PLAYLISTS)))
class TSongsMenuPlugins(TestCase): def setUp(self): self.tempdir = mkdtemp() self.pm = PluginManager(folders=[self.tempdir]) self.handler = SongsMenuPluginHandler() self.pm.register_handler(self.handler) self.pm.rescan() self.assertEquals(self.pm.plugins, []) def tearDown(self): self.pm.quit() for f in os.listdir(self.tempdir): os.remove(os.path.join(self.tempdir,f)) os.rmdir(self.tempdir) def create_plugin(self, id= '', name='', desc='', icon='', funcs=None, mod=False): fd, fn = mkstemp(suffix='.py', text=True, dir=self.tempdir) file = os.fdopen(fd, 'w') if mod: indent = '' else: file.write("from quodlibet.plugins.songsmenu import SongsMenuPlugin\n") file.write("class %s(SongsMenuPlugin):\n" % name) indent = ' ' file.write("%spass\n" % indent) if name: file.write("%sPLUGIN_ID = %r\n" % (indent, name)) if name: file.write("%sPLUGIN_NAME = %r\n" % (indent, name)) if desc: file.write("%sPLUGIN_DESC = %r\n" % (indent, desc)) if icon: file.write("%sPLUGIN_ICON = %r\n" % (indent, icon)) for f in (funcs or []): if f in ["__init__"]: file.write("%sdef %s(*args): pass\n" % (indent, f)) else: file.write("%sdef %s(*args): return args\n" % (indent, f)) file.flush() file.close() def test_empty_has_no_plugins(self): self.pm.rescan() self.assertEquals(self.pm.plugins, []) def test_name_and_desc_plus_func_is_one(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) def test_additional_functions_still_only_one(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song', 'plugin_songs']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 1) def test_two_plugins_are_two(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song']) self.create_plugin(name='Name2', desc='Desc2', funcs=['plugin_albums']) self.pm.rescan() self.assertEquals(len(self.pm.plugins), 2) def test_disables_plugin(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song']) self.pm.rescan() self.failIf(self.pm.enabled(self.pm.plugins[0])) def test_enabledisable_plugin(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song']) self.pm.rescan() plug = self.pm.plugins[0] self.pm.enable(plug, True) self.failUnless(self.pm.enabled(plug)) self.pm.enable(plug, False) self.failIf(self.pm.enabled(plug)) def test_ignores_broken_plugin(self): self.create_plugin(name="Broken", desc="Desc", funcs=["__init__", "plugin_song"]) self.pm.rescan() plug = self.pm.plugins[0] self.pm.enable(plug, True) menu = self.handler.Menu(None, None, [AudioFile()]) self.failIf(menu and menu.get_children()) def test_Menu(self): self.create_plugin(name='Name', desc='Desc', funcs=['plugin_song']) self.handler.Menu(None, None, [AudioFile()])
def test_show_uri_with_existing_window(self): PluginManager.instance = PluginManager() # Force an instance PluginWindow() qltk.show_uri("foo", "quodlibet:///prefs/plugins/Squeezebox Output")