aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unittests/option_tests.py
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2021-08-11 17:11:17 -0400
committerJake Hunsaker <jhunsake@redhat.com>2021-08-30 10:26:24 -0400
commit0b6dc021b7ae54688fca70168c70744ad752834a (patch)
treecec639f6e5ddc8226e47792b85c93a8f118f98fe /tests/unittests/option_tests.py
parent2b8f029004f4f93b9bdadc47e32fe587591f88f4 (diff)
downloadsos-0b6dc021b7ae54688fca70168c70744ad752834a.tar.gz
[Plugin] Make plugin options their own class
Up until now plugin options were defined via tuples, with positional significance of the tuple elements. This made plugin option creation fairly easy, but option handling could easily become confusing. Instead, create a new `PluginOpt` class that plugin options from here on out will need to build from in order to function. These will still be applied to plugins by inserting them into the `option_list` class attr in order to retain an easy way to expand plugin options for authors. Internally, options are now assigned to a dict which is then directly accessed for plugin option manipulations. PluginOpt default values are retained separate from their current value, and elements are assigned directly to meaningful identifiers within the class. This should alleviate some of the overhead when handling plugin options within sos. Not all current tuple elements have been carried over into the new `PluginOpt` class - for example, the 'speed' attribute has been dropped as it does not have a current function. In the planned `sos info` component, the time effects of a plugin option should be documented in the `long_desc` attribute instead. Additionally, the `Plugin.get_option_as_list()` method has been removed as it was not being used anywhere. Note that this particular commit only introduces the new class, and the loading options used by `SoSReport()`. As such, plugins using options currently will report errors during test runs. A commit following this one will shuffle existing plugin options into the new class structure and allow the plugins to execute normally. Resolves: #274 Resolves: #452 Resolves: #1597 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests/unittests/option_tests.py')
-rw-r--r--tests/unittests/option_tests.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/tests/unittests/option_tests.py b/tests/unittests/option_tests.py
index 58f54e94..4a9271ad 100644
--- a/tests/unittests/option_tests.py
+++ b/tests/unittests/option_tests.py
@@ -7,7 +7,7 @@
# See the LICENSE file in the source distribution for further information.
import unittest
-from sos.report.plugins import Plugin
+from sos.report.plugins import Plugin, PluginOpt
from sos.policies.distros import LinuxPolicy
from sos.policies.init_systems import InitSystem
@@ -21,6 +21,18 @@ class MockOptions(object):
skip_files = []
+class MockPlugin(Plugin):
+
+ option_list = [
+ PluginOpt('baz', default=False),
+ PluginOpt('empty', default=None),
+ PluginOpt('test_option', default='foobar')
+ ]
+
+ def __init__(self, commons):
+ super(MockPlugin, self).__init__(commons=commons)
+
+
class GlobalOptionTest(unittest.TestCase):
def setUp(self):
@@ -30,11 +42,7 @@ class GlobalOptionTest(unittest.TestCase):
'cmdlineopts': MockOptions(),
'devices': {}
}
- self.plugin = Plugin(self.commons)
- self.plugin.opt_names = ['baz', 'empty', 'test_option']
- self.plugin.opt_parms = [
- {'enabled': False}, {'enabled': None}, {'enabled': 'foobar'}
- ]
+ self.plugin = MockPlugin(self.commons)
def test_simple_lookup(self):
self.assertEquals(self.plugin.get_option('test_option'), 'foobar')