Module: check_mk
Branch: master
Commit: 04f422ecf6baaff7b204f15960cf0d66a6bbfdeb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=04f422ecf6baaf…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Tue Dec 11 13:41:09 2018 +0100
Minor fix and some cleanups in generictests
* only expect a discovery function if services were discovered in run.py
* move check.default_parameters() into get_merged_parameters in run.py
* remove mutable default argument from WritableDataset in regression.py
* remove unused pytest import in regression.py
* reorder imports in checkhandler.py
Change-Id: I233539816f5562626ac690ab71391e5e04c3e303
---
tests/unit/checks/generictests/checkhandler.py | 5 ++++-
tests/unit/checks/generictests/regression.py | 4 ++--
tests/unit/checks/generictests/run.py | 31 +++++++++++---------------
3 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/tests/unit/checks/generictests/checkhandler.py
b/tests/unit/checks/generictests/checkhandler.py
index 03792c2..bd27d5a 100644
--- a/tests/unit/checks/generictests/checkhandler.py
+++ b/tests/unit/checks/generictests/checkhandler.py
@@ -1,9 +1,12 @@
+import copy
+
import cmk_base.config as config
import cmk_base.check_api as check_api
-import copy
+
class CheckHandler(object):
"""Collect the info on all checks"""
+
def __init__(self):
config.load_all_checks(check_api.get_check_api_context)
self.info = copy.deepcopy(config.check_info)
diff --git a/tests/unit/checks/generictests/regression.py
b/tests/unit/checks/generictests/regression.py
index 2f58550..003100d 100644
--- a/tests/unit/checks/generictests/regression.py
+++ b/tests/unit/checks/generictests/regression.py
@@ -36,16 +36,16 @@ Make sure the file(s name) is a valid python module:
~/git/check_mk/tests/unit/checks/generictests/datasets/nfsmounts_1.py
"""
-import pytest
import os
import sys
import pprint
from importlib import import_module
+
import generictests.run
class WritableDataset(object):
- def __init__(self, filename, init_dict={}):
+ def __init__(self, filename, init_dict):
self.comments = ['']
self.filename = filename
self.writelist = (
diff --git a/tests/unit/checks/generictests/run.py
b/tests/unit/checks/generictests/run.py
index b45ff6d..a820c67 100644
--- a/tests/unit/checks/generictests/run.py
+++ b/tests/unit/checks/generictests/run.py
@@ -17,7 +17,7 @@ def get_info_argument(dataset, subcheck, fallback_parsed=None):
This may be the info variable, the parsed variable,
and/or including extra sections.
"""
- # see i fwe have a parsed result defined
+ # see if we have a parsed result defined
tmp = getattr(dataset, 'parsed', None)
if tmp is not None:
arg = [tmp]
@@ -40,24 +40,24 @@ def get_info_argument(dataset, subcheck, fallback_parsed=None):
return arg
-def get_merged_parameters(default_p, provided_p):
+def get_merged_parameters(check, provided_p):
"""return (merged_params, description_string)
I think this is a mess.
I'm trying to do the right thing, any ideas wellcome.
"""
+ default_p = check.default_parameters()
+
if not provided_p:
return default_p, "default"
- elif isinstance(provided_p, str):
+ if isinstance(provided_p, str):
return default_p, "default"
- elif type(default_p) == type(provided_p) == dict:
+ if isinstance(default_p, dict) and isinstance(provided_p, dict):
default_p.update(provided_p)
return default_p, repr(default_p)
- elif not default_p:
+ if not default_p:
return provided_p, repr(provided_p)
-
- raise DiscoveryParameterTypeError("unhandled: %r/%r" \
- % (default_p, provided_p))
+ raise DiscoveryParameterTypeError("unhandled: %r/%r" % (default_p,
provided_p))
def get_mock_values(dataset, subcheck):
@@ -108,7 +108,7 @@ def discovery(check, subcheck, dataset, info_arg, immu):
discov_expected = getattr(dataset, 'discovery', {})
disco_func = check.info.get("inventory_function")
- if subcheck in discov_expected:
+ if discov_expected.get(subcheck):
# we *must* have a discovery function in this case!
assert disco_func, "%r has no discovery function!" \
% check.name
@@ -127,18 +127,14 @@ def discovery(check, subcheck, dataset, 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,
- but at least make sure we don't crash.
+ """Run the check on all discovered items with the default parameters.
+ We cannot validate the results, but at least make sure we don't crash.
"""
print("Check %r in check %r" % (discovery_result, check.name))
item = discovery_result.item
- disco_params = discovery_result.default_params
- def_params = check.default_parameters()
- params, par_str = get_merged_parameters(def_params, disco_params)
+ params, par_str = get_merged_parameters(check, discovery_result.default_params)
immu.register(params, 'params')
raw_checkresult = check.run_check(item, params, info_arg)
@@ -155,8 +151,7 @@ def check_listed_result(check, list_entry, info_arg, immu):
item, params, results_expected_raw = list_entry
print("Dataset item %r in check %r" % (item, check.name))
- default_params = check.default_parameters()
- params, __ = get_merged_parameters(default_params, params)
+ params, __ = get_merged_parameters(check, params)
immu.register(params, 'params')
result_raw = check.run_check(item, params, info_arg)