Module: check_mk
Branch: master
Commit: eb3b46028dd8cfe365fc7eb206f43f51b1ef4f8b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eb3b46028dd8cf…
Author: Kenneth Okoh <ko(a)mathias-kettner.de>
Date: Fri Oct 12 14:42:00 2018 +0200
Check function decorator: Adjusted for item in parsed but parsed[item] empty
Change-Id: I18d97315821b349fb8bd398ef8e49eb0015b7db9
---
cmk_base/check_api.py | 9 +++++----
tests/unit/cmk_base/test_check_api.py | 5 ++++-
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/cmk_base/check_api.py b/cmk_base/check_api.py
index 888edfa..721ffe5 100644
--- a/cmk_base/check_api.py
+++ b/cmk_base/check_api.py
@@ -492,15 +492,16 @@ def get_parsed_item_data(check_function):
In case of parsed not being a dict the decorator returns 3
(UNKN state) with a wrong usage message.
- In case of item not existing in parsed the decorator gives an
- empty return leading to cmk_base returning 3 (UNKN state) with
- an item not found message (see cmk_base/checking.py).
+ In case of item not existing as a key in parsed or parsed[item]
+ not existing the decorator gives an empty return leading to
+ cmk_base returning 3 (UNKN state) with an item not found message
+ (see cmk_base/checking.py).
"""
@_functools.wraps(check_function)
def wrapped_check_function(item, params, parsed):
if not isinstance(parsed, dict):
return 3, "Wrong usage of decorator function 'get_parsed_item_data': parsed is not a dict"
- if item not in parsed:
+ if item not in parsed or not parsed[item]:
return
return check_function(item, params, parsed[item])
return wrapped_check_function
diff --git a/tests/unit/cmk_base/test_check_api.py b/tests/unit/cmk_base/test_check_api.py
index 2222e31..a300832 100644
--- a/tests/unit/cmk_base/test_check_api.py
+++ b/tests/unit/cmk_base/test_check_api.py
@@ -12,10 +12,13 @@ def check_foo(item, params, parsed_item_data):
def test_get_parsed_item_data():
params = {}
- parsed = {1: "one"}
+ parsed = {1: "one", 3: {}, 4: [], 5: ""}
info = [[1, "one"], [2, "two"]]
assert check_foo(1, params, parsed) == (2, "bar")
assert check_foo(2, params, parsed) == None
+ assert check_foo(3, params, parsed) == None
+ assert check_foo(4, params, parsed) == None
+ assert check_foo(5, params, parsed) == None
assert check_foo(1, params, info) == (3, "Wrong usage of decorator function 'get_parsed_item_data': parsed is not a dict")
assert check_foo.__name__ == "check_foo"
Module: check_mk
Branch: master
Commit: e3cbd03d72131a8661099f4a22ab68f6fad8fd52
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e3cbd03d72131a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sat Oct 13 15:00:55 2018 +0200
Add typing info to fix jedi completion of and mypy validation of html object
Change-Id: I59f6f27492ce06c00e0f9e9dd8125610ca0a6ea6
---
cmk/gui/globals.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/cmk/gui/globals.py b/cmk/gui/globals.py
index a44cfb4..a4821e7 100644
--- a/cmk/gui/globals.py
+++ b/cmk/gui/globals.py
@@ -24,10 +24,10 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-# Previously the current html object was available to all GUI code via the
-# __builtin__ namespace while processing a request. This was tool friendly
-# and has been replaced with this mechanism. We have a proxy object which
-# forwards all requests to the html() object of the current request.
+# Imports are needed for type hints. These type hints are useful for
+# editors completion of "html" object methods and for mypy.
+from typing import Union # pylint: disable=unused-import
+import cmk.gui.htmllib # pylint: disable=unused-import
class HTMLProxy(object):
def __init__(self):
@@ -61,4 +61,4 @@ class HTMLProxy(object):
return repr(self._current_html)
-html = HTMLProxy()
+html = HTMLProxy() # type: Union[cmk.gui.htmllib.html, HTMLProxy]