Module: check_mk
Branch: master
Commit: 1a74e8acc73e185e632ac816fd1f56110ec3a2f9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1a74e8acc73e18…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Wed Dec 20 13:52:32 2017 +0100
checktestlib: Generalize CompoundCheckResult to also handle the non-yield case. Rename
accordingly, remove calls to BasicCheckResult in tests
Change-Id: I7fe8a980f520a31c0d551dd66e3cd3d2fdeea15d
---
tests/checks/checktestlib.py | 21 +++++++++++++++------
tests/checks/test_df_check.py | 2 +-
tests/checks/test_statgrab_cpu_check.py | 2 +-
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/tests/checks/checktestlib.py b/tests/checks/checktestlib.py
index 2b65354..c8a723d 100644
--- a/tests/checks/checktestlib.py
+++ b/tests/checks/checktestlib.py
@@ -1,3 +1,5 @@
+import types
+
class PerfValue(object):
"""Represents a single perf value"""
@@ -52,12 +54,19 @@ class BasicCheckResult(object):
self.perfdata = None
-class CompoundCheckResult(object):
- """A check result consisting of multiple subresults, as returned by
yield-style checks"""
+class CheckResult(object):
+ """A check result potentially consisting of multiple subresults, as
returned by yield-style checks"""
def __init__(self, result):
- """Initializes a list of subresults using
BasicCheckResult"""
+ """Initializes a list of subresults using BasicCheckResult.
+
+ If the result is already a plain check result in its tuple representation, we
initialize
+ a list of length 1.
+ """
- self.subresults = []
- for subresult in result:
- self.subresults.append(BasicCheckResult(*subresult))
+ if type(result) == types.GeneratorType:
+ self.subresults = []
+ for subresult in result:
+ self.subresults.append(BasicCheckResult(*subresult))
+ else:
+ self.subresults = [ BasicCheckResult(*result) ]
diff --git a/tests/checks/test_df_check.py b/tests/checks/test_df_check.py
index d02e698..ce8386e 100644
--- a/tests/checks/test_df_check.py
+++ b/tests/checks/test_df_check.py
@@ -266,4 +266,4 @@ def test_df_check_with_parse(check_manager, monkeypatch, item, params,
info, exp
if params == "default":
params = check.default_parameters()
- result = checktestlib.BasicCheckResult(*check.run_check(item, params,
check.run_parse(info)))
+ result = checktestlib.CheckResult(check.run_check(item, params,
check.run_parse(info)))
diff --git a/tests/checks/test_statgrab_cpu_check.py
b/tests/checks/test_statgrab_cpu_check.py
index 711e213..cfec920 100644
--- a/tests/checks/test_statgrab_cpu_check.py
+++ b/tests/checks/test_statgrab_cpu_check.py
@@ -26,4 +26,4 @@ def test_statgrab_cpu_check(check_manager, monkeypatch, time_to_info,
params, ex
except MKCounterWrapped:
pass
monkeypatch.setattr("time.time", lambda: 60)
- result = checktestlib.CompoundCheckResult(check.run_check(None, params,
time_to_info(60)))
+ result = checktestlib.CheckResult(check.run_check(None, params, time_to_info(60)))