Module: check_mk
Branch: master
Commit: aeac34f94114a26208d4aa49f54c2166867e85a7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=aeac34f94114a2…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Jun 21 08:21:16 2018 +0200
Skip explicit creation of BasicCheckResult
We can now create a CheckResult from plain tuples,
without the need to create an BasicCheckResult explicitly.
This is in analogy to the way we can create BasicCheckResults
without explicitly creating PerfValue objects.
This leads to more concise tests.
Change-Id: Ia321ec61b90d4471fad8cd1487dc174706a84194
---
tests/unit/checks/checktestlib.py | 11 +++++++++--
tests/unit/checks/test_statgrab_cpu_check.py | 21 ++++++++++-----------
2 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/tests/unit/checks/checktestlib.py b/tests/unit/checks/checktestlib.py
index 85ad02c..3cf1e8f 100644
--- a/tests/unit/checks/checktestlib.py
+++ b/tests/unit/checks/checktestlib.py
@@ -139,9 +139,16 @@ class CheckResult(object):
if isinstance(result, types.GeneratorType):
for subresult in result:
self.subresults.append(BasicCheckResult(*subresult))
- # creation of a CheckResult via a list of BasicCheckResult for test writing
+ # creation of a CheckResult via a list of
+ # tuple or BasicCheckResult for test writing
elif isinstance(result, list):
- assert all(isinstance(subresult, BasicCheckResult) for subresult in result)
+ for subresult in result:
+ assert type(subresult) in (tuple, BasicCheckResult), \
+ "type of subresult must be %s or %s - not %r" % \
+ (tuple, BasicCheckResult, subresult)
+ if isinstance(subresult, tuple):
+ subresult = BasicCheckResult(*subresult)
+ self.subresults.append(subresult)
self.subresults = result
else:
self.subresults.append(BasicCheckResult(*result))
diff --git a/tests/unit/checks/test_statgrab_cpu_check.py
b/tests/unit/checks/test_statgrab_cpu_check.py
index a3a47e7..0ef9645 100644
--- a/tests/unit/checks/test_statgrab_cpu_check.py
+++ b/tests/unit/checks/test_statgrab_cpu_check.py
@@ -1,7 +1,6 @@
import pytest
-from checktestlib import BasicCheckResult, CheckResult, \
- assertCheckResultsEqual, BasicItemState, \
- MockItemState, assertMKCounterWrapped
+from checktestlib import CheckResult, assertCheckResultsEqual, \
+ BasicItemState, MockItemState, assertMKCounterWrapped
pytestmark = pytest.mark.checks
@@ -52,26 +51,26 @@ def mock_state_function(key, _default):
# TODO: These only represent the status quo - check whether they even make sense.
# Note that systime and total are being ignored entirely by the check.
expected_result_1 = CheckResult([
- BasicCheckResult(0, "user: 40.0%, system: 20.0%",
+ (0, "user: 40.0%, system: 20.0%",
[('user', 40.0, None, None, None, None),
('system', 20.0, None, None, None, None),
('wait', 20.0, None, None, None, None)]),
- BasicCheckResult(0, "wait: 20.0%", None),
- BasicCheckResult(0, "steal: 0.0%",
+ (0, "wait: 20.0%", None),
+ (0, "steal: 0.0%",
[('steal', 0.0, None, None, None, None)]),
- BasicCheckResult(0, "total: 80.0%", None)
+ (0, "total: 80.0%", None)
])
expected_result_2 = CheckResult([
- BasicCheckResult(0, "user: -51.6%, system: -105.8%",
+ (0, "user: -51.6%, system: -105.8%",
[('user', -51.61290322580645, None, None, None, None),
('system', -105.80645161290323, None, None, None, None),
('wait', 451.61290322580646, None, None, None, None)]),
- BasicCheckResult(0, "wait: 451.6%", None),
- BasicCheckResult(0, "steal: 78.7%",
+ (0, "wait: 451.6%", None),
+ (0, "steal: 78.7%",
[('steal', 78.70967741935483, None, None, None, None)]),
- BasicCheckResult(0, "total: 372.9%", None)
+ (0, "total: 372.9%", None)
])