Module: check_mk
Branch: master
Commit: 69c2b72105b30c6a23d9824a34fbea843527521b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=69c2b72105b30c…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Tue Dec 11 13:28:20 2018 +0100
Format regression.py and run.py
Change-Id: If4ae7a1850a0d4d009c70b1ce4c347f63246fc44
---
tests/unit/checks/generictests/regression.py | 30 +++++++++++++++++-----------
tests/unit/checks/generictests/run.py | 27 +++++++++----------------
2 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/tests/unit/checks/generictests/regression.py
b/tests/unit/checks/generictests/regression.py
index 0b2cbe0..2f58550 100644
--- a/tests/unit/checks/generictests/regression.py
+++ b/tests/unit/checks/generictests/regression.py
@@ -48,15 +48,23 @@ class WritableDataset(object):
def __init__(self, filename, init_dict={}):
self.comments = ['']
self.filename = filename
- self.writelist = ('checkname', 'info', 'parsed',
'discovery',
- 'checks', 'extra_sections', 'mock_host_conf',
'mock_item_state')
- self.checkname = init_dict.get('checkname', None)
- self.info = init_dict.get('info', None)
- self.parsed = init_dict.get('parsed', None)
- self.discovery = init_dict.get('discovery', {})
- self.checks = {}
- self.extra_sections = init_dict.get('extra_sections', {})
- self.mock_host_conf = init_dict.get('mock_host_conf', {})
+ self.writelist = (
+ 'checkname',
+ 'info',
+ 'parsed',
+ 'discovery',
+ 'checks',
+ 'extra_sections',
+ 'mock_host_conf',
+ 'mock_item_state',
+ )
+ self.checkname = init_dict.get('checkname', None)
+ self.info = init_dict.get('info', None)
+ self.parsed = init_dict.get('parsed', None)
+ self.discovery = init_dict.get('discovery', {})
+ self.checks = {}
+ self.extra_sections = init_dict.get('extra_sections', {})
+ self.mock_host_conf = init_dict.get('mock_host_conf', {})
self.mock_item_state = init_dict.get('mock_item_state', {})
def write(self):
@@ -88,11 +96,9 @@ def test_main(check_manager, datasetfile):
input_data = import_module(os.path.splitext(modn)[0])
sys.path.pop(0)
- regression = WritableDataset(datasetfile.replace('.py',
'_regression.py'),
- vars(input_data))
+ regression = WritableDataset(datasetfile.replace('.py',
'_regression.py'), vars(input_data))
generictests.run(check_manager, regression, write=True)
regression.write()
return
-
diff --git a/tests/unit/checks/generictests/run.py
b/tests/unit/checks/generictests/run.py
index e70bf96..b45ff6d 100644
--- a/tests/unit/checks/generictests/run.py
+++ b/tests/unit/checks/generictests/run.py
@@ -11,7 +11,7 @@ class DiscoveryParameterTypeError(AssertionError):
pass
-def get_info_argument(dataset, subcheck, fallback_parsed=None):# .
+def get_info_argument(dataset, subcheck, fallback_parsed=None):
"""Get the argument to the discovery/check function
This may be the info variable, the parsed variable,
@@ -29,8 +29,7 @@ def get_info_argument(dataset, subcheck, fallback_parsed=None):# .
try:
arg = [dataset.info]
except AttributeError:
- raise AttributeError("dataset has neither of the attributes "
- "'info' or 'parsed'")
+ raise AttributeError("dataset has neither of the attributes "
"'info' or 'parsed'")
es_dict = getattr(dataset, 'extra_sections', {})
for es in es_dict.get(subcheck, []):
@@ -39,10 +38,9 @@ def get_info_argument(dataset, subcheck, fallback_parsed=None):# .
if len(arg) == 1:
return arg[0]
return arg
-#.
-def get_merged_parameters(default_p, provided_p):# .
+def get_merged_parameters(default_p, provided_p):
"""return (merged_params, description_string)
I think this is a mess.
@@ -60,17 +58,15 @@ def get_merged_parameters(default_p, provided_p):# .
raise DiscoveryParameterTypeError("unhandled: %r/%r" \
% (default_p, provided_p))
-#.
-def get_mock_values(dataset, subcheck):# .
+def get_mock_values(dataset, subcheck):
mock_is_d = getattr(dataset, 'mock_item_state', {})
mock_hc_d = getattr(dataset, 'mock_host_conf', {})
return mock_is_d.get(subcheck, {}), mock_hc_d.get(subcheck, {})
-#.
-def parse(check_manager, dataset):# .
+def parse(check_manager, dataset):
"""Test parse function
If dataset has .info attribute and the check has parse function defined,
@@ -96,17 +92,16 @@ def parse(check_manager, dataset):# .
# we *must* have a parse function in this case!
assert parse_function, "%s has no parse function!" \
% dataset.checkname
- elif not parse_function: # we may not have one:
+ elif not parse_function: # we may not have one:
return None
parsed = main_check.run_parse(info)
if parsed_expected is not None:
assertEqual(parsed, parsed_expected, ' parsed result ')
return parsed
-#.
-def discovery(check, subcheck, dataset, info_arg, immu):# .
+def discovery(check, subcheck, dataset, info_arg, immu):
"""Test discovery funciton, return discovery result"""
print("discovery: %r" % check.name)
@@ -129,10 +124,9 @@ def discovery(check, subcheck, dataset, info_arg, immu):# .
assertDiscoveryResultsEqual(d_result, d_result_expected)
return d_result
-#.
-def check_discovered_result(check, discovery_result, info_arg, immu):# .
+def check_discovered_result(check, discovery_result, info_arg, immu):
"""Run the check on all discovered items
with the default parameters. We cannot validate the results,
@@ -154,10 +148,9 @@ def check_discovered_result(check, discovery_result, info_arg,
immu):# .
cr = CheckResult(raw_checkresult)
return (item, par_str, cr.raw_repr())
-#.
-def check_listed_result(check, list_entry, info_arg, immu):# .
+def check_listed_result(check, list_entry, info_arg, immu):
"""Run check for all results listed in dataset"""
item, params, results_expected_raw = list_entry
print("Dataset item %r in check %r" % (item, check.name))
@@ -173,7 +166,6 @@ def check_listed_result(check, list_entry, info_arg, immu):# .
result = CheckResult(result_raw)
result_expected = CheckResult(results_expected_raw)
assertCheckResultsEqual(result, result_expected)
-#.
def run(check_manager, dataset, write=False):
@@ -190,7 +182,6 @@ def run(check_manager, dataset, write=False):
# get the expected check results, if present
checks_expected = getattr(dataset, 'checks', {})
-
# LOOP OVER ALL (SUB)CHECKS
for sname in checklist:
subcheck = (sname + '.').split('.')[1]