File: test_style.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 (82 lines) | stat: -rw-r--r-- 3,034 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2015 Anton Shestakov
#           2021 Nick Boultbee
#
# 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 tests.helper import ListWithUnused as L
from tests.plugin import PluginTestCase
from quodlibet.util.string.titlecase import human_title


class TPluginStyle(PluginTestCase):
    def conclude(self, fails):
        def format_msg(f):
            return "%s: '%s' plugin (%s)" % (f[1], f[0].name, f[0].cls)
        if not fails:
            return
        grouped = {}
        for f in fails:
            grouped.setdefault(f[2], []).append(f)
        lines = []
        for reason in grouped:
            lines.append('== ' + reason + ' ==')
            for f in grouped[reason]:
                plugin, string = f[:2]
                pclass = plugin.cls.__name__
                ppath = plugin.cls.__module__.rpartition('.plugins.')[2]
                lines.append("%s.%s: %r" % (ppath, pclass, string))
        self.fail("One or more plugins did not pass:\n" + '\n'.join(lines))

    def test_plugin_name(self):
        REASON_ABSENT = "plugin should have PLUGIN_NAME"
        REASON_CASE = "PLUGIN_NAME should be in Title Case"

        ok_names = L(
            'Last.fm Cover Source', 'Last.fm Sync', 'Send to iFP',
            'This is a test')
        fails = []

        for pid, plugin in self.plugins.items():
            if not hasattr(plugin.cls, 'PLUGIN_NAME'):
                fails.append((plugin, None, REASON_ABSENT))
                continue
            name = plugin.cls.PLUGIN_NAME
            if name != human_title(name):
                if name not in ok_names:
                    fails.append((plugin, name, REASON_CASE))

        ok_names.check_unused()
        self.conclude(fails)

    def test_plugin_desc(self):
        REASON_ABSENT = "plugin should have PLUGIN_DESC or PLUGIN_DESC_MARKUP"
        REASON_DOT = ("PLUGIN_DESC / PLUGIN_DESC_MARKUP "
                      "should be a full sentence and end with a '.'")

        skip_plugins = L('pickle_plugin')
        fails = []

        for pid, plugin in self.plugins.items():
            cls = plugin.cls
            if pid in skip_plugins:
                continue
            got = 0
            if hasattr(cls, 'PLUGIN_DESC'):
                got += 1
                desc = cls.PLUGIN_DESC
                if not desc.endswith('.'):
                    fails.append((plugin, desc, REASON_DOT))
                    continue
            if hasattr(cls, "PLUGIN_DESC_MARKUP"):
                got += 1
                desc = cls.PLUGIN_DESC_MARKUP
                if not desc.endswith('.'):
                    fails.append((plugin, desc, REASON_DOT))
                    continue
            if not got:
                fails.append((plugin, None, REASON_ABSENT))
        skip_plugins.check_unused()
        self.conclude(fails)