File: test_console.py

package info (click to toggle)
quodlibet 4.6.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,016 kB
  • sloc: python: 85,817; sh: 385; xml: 110; makefile: 91
file content (60 lines) | stat: -rw-r--r-- 1,712 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Copyright 2017 Christoph Reiter
#           2021 halfbrained@github
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

from gi.repository import Gtk

from quodlibet.formats import AudioFile
from quodlibet.util.songwrapper import SongWrapper
from tests.plugin import PluginTestCase

AUDIO_FILE = SongWrapper(AudioFile({'~filename': "/tmp/foobar"}))


class Dummy:
    dummy_val = "str!"

    def dummy_meth(self, arg, varg=101):
        pass


DUMMY_COMPLETIONS = [
    ('dummy_meth', ' (arg, varg=101)'),
    ('dummy_val', ''),
]
NAMESPACE_COMPLETIONS = ('dummy', '')


class TConsole(PluginTestCase):
    def setUp(self):
        self.mod = self.modules["Python Console Sidebar"]

    def tearDown(self):
        del self.mod

    def test_sidebar_plugin(self):
        plugin = self.mod.PyConsoleSidebar()
        plugin.enabled()
        self.failUnless(isinstance(plugin.create_sidebar(), Gtk.Widget), True)
        plugin.plugin_on_songs_selected([AUDIO_FILE])
        self.failUnlessEqual(plugin.console.namespace.get('songs'),
                             [AUDIO_FILE])
        plugin.disabled()

    def test_console_completion(self):
        plugin = self.mod.PyConsoleSidebar()
        plugin.enabled()

        plugin.console.namespace['dummy'] = Dummy()

        comp = plugin.console.get_completion_items('dummy.')
        self.failUnlessEqual(comp, DUMMY_COMPLETIONS)

        comp = plugin.console.get_completion_items('')
        assert NAMESPACE_COMPLETIONS in comp

        plugin.disabled()