aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unittests/conformance_tests.py
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2021-05-17 23:27:17 -0400
committerJake Hunsaker <jhunsake@redhat.com>2021-05-19 10:47:15 -0400
commite6fe798b06d954b3e90380acb419a8aff2706f21 (patch)
treee7deff98b004c70701e39c739c324f67c2aaf138 /tests/unittests/conformance_tests.py
parentf12ba9f9cf66f10064ca20a23a719d520c6f4aab (diff)
downloadsos-e6fe798b06d954b3e90380acb419a8aff2706f21.tar.gz
[tests] Add test for plugin design conformance
Adds a unittest that ensures conformance for plugin design, e.g. ensuring that enablement triggers are proper tuples and not inadvertent strings due to a missing trailing comma for single-tuples. Resolves: #2549 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests/unittests/conformance_tests.py')
-rw-r--r--tests/unittests/conformance_tests.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/unittests/conformance_tests.py b/tests/unittests/conformance_tests.py
new file mode 100644
index 00000000..93814a77
--- /dev/null
+++ b/tests/unittests/conformance_tests.py
@@ -0,0 +1,57 @@
+# 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
+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']:
+ _attr = getattr(plug, tup)
+ self.assertIsInstance(
+ _attr, tuple,
+ "%s.%s is type %s" % (plug.__name__, tup, type(_attr))
+ )
+
+ def test_plugin_description_is_str(self):
+ for plug in self.plug_classes:
+ self.assertIsInstance(plug.short_desc, str, "%s name not string" % plug.__name__)
+ # make sure the description is not empty
+ self.assertNotEqual(plug.short_desc, '',
+ "%s description unset" % plug.__name__)
+
+ def test_plugin_name_is_str(self):
+ for plug in self.plug_classes:
+ self.assertIsInstance(plug.plugin_name, str, "%s name not string" % plug.__name__)
+ self.assertNotEqual(plug.plugin_name, '',
+ "%s name unset" % plug.__name__)
+
+ 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, tuple)
+
+ def test_plugin_architectures_set_correctly(self):
+ for plug in self.plug_classes:
+ self.assertIsInstance(plug.architectures, (tuple, type(None)))