aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unittests/conformance_tests.py
blob: ea337624f0c33be4a1b973038406dd3022d2cc22 (plain) (blame)
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
# This file is part of the sos project: https://github.com/sosreport/sos
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# version 2 of the GNU General Public License.
#
# See the LICENSE file in the source distribution for further information.
import unittest


from sos.report.plugins import import_plugin, PluginOpt
from sos.utilities import ImporterHelper


class PluginConformance(unittest.TestCase):

    def setUp(self):
        # get all plugin classes defined locally
        import sos.report.plugins
        self.plugs = []
        self.plug_classes = []
        helper = ImporterHelper(sos.report.plugins)
        self.plugs = helper.get_modules()
        for plug in self.plugs:
            self.plug_classes.extend(import_plugin(plug))

    def test_plugin_tuples_set_correctly(self):
        for plug in self.plug_classes:
            for tup in ['packages', 'commands', 'files', 'profiles',
                        'kernel_mods', 'containers']:
                _attr = getattr(plug, tup)
                self.assertIsInstance(
                    _attr, tuple,
                    f"{plug.__name__}.{tup} is type {type(_attr)}"
                )

    def test_plugin_description_is_str(self):
        for plug in self.plug_classes:
            self.assertIsInstance(plug.short_desc, str,
                                  f"{plug.__name__} name not string")
            # make sure the description is not empty
            self.assertNotEqual(plug.short_desc, '',
                                f"{plug.__name__} description unset")

    def test_plugin_name_is_str(self):
        for plug in self.plug_classes:
            self.assertIsInstance(plug.plugin_name, str,
                                  f"{plug.__name__} name not string")
            self.assertNotEqual(plug.plugin_name, '',
                                f"{plug.__name__} name unset")

    def test_plugin_option_list_correct(self):
        for plug in self.plug_classes:
            self.assertIsInstance(plug.option_list, list)
            for opt in plug.option_list:
                self.assertIsInstance(opt, PluginOpt)
                self.assertFalse(opt.name == 'undefined')

    def test_plugin_architectures_set_correctly(self):
        for plug in self.plug_classes:
            self.assertIsInstance(plug.architectures, (tuple, type(None)))