Module: check_mk
Branch: master
Commit: 8d90593584c002e8da94275a413b419eced0e4eb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8d90593584c002…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Oct 19 09:25:26 2018 +0200
checktestlib.py: Produce more helpful output
Change-Id: Ia5e20027849f0cf4b16c00748d102396c64dcb4b
---
tests/unit/checks/checktestlib.py | 44 ++++++++++++++++++++++++++++++++-------
1 file changed, 37 insertions(+), 7 deletions(-)
diff --git a/tests/unit/checks/checktestlib.py b/tests/unit/checks/checktestlib.py
index adbc552..e22049c 100644
--- a/tests/unit/checks/checktestlib.py
+++ b/tests/unit/checks/checktestlib.py
@@ -11,7 +11,7 @@ class Tuploid(object):
if isinstance(other_value, self.__class__):
return other_value.tuple == self.tuple
elif type(other_value) == tuple:
- return all(x==y for x, y in zip(other_value, self.tuple))
+ return all(x == y for x, y in zip(other_value, self.tuple))
def __ne__(self, other_value):
return not self.__eq__(other_value)
@@ -25,7 +25,6 @@ class Tuploid(object):
yield x
-
class PerfValue(Tuploid):
"""Represents a single perf value"""
@@ -69,6 +68,23 @@ class PerfValue(Tuploid):
return "PerfValue(%r, %r, %r, %r, %r, %r)" % self.tuple
+def assertPerfValuesEqual(actual, expected):
+ """
+ Compare two PerfValues.
+
+ This gives more helpful output than 'assert actual == expected'
+ """
+ assert isinstance(actual, PerfValue), "not a PerfValue: %r" % actual
+ assert isinstance(expected, PerfValue), "not a PerfValue: %r" % expected
+ assert expected.key == actual.key, "expected %r, but key is %r" %
(expected, actual.key)
+ assert expected.value == actual.value, "expected %r, but value is %r" %
(expected, actual.value)
+ assert expected.warn == actual.warn, "expected %r, but warn is %r" %
(expected, actual.warn)
+ assert expected.crit == actual.crit, "expected %r, but crit is %r" %
(expected, actual.crit)
+ assert expected.minimum == actual.minimum, "expected %r, but minimum is %r"
% (expected, actual.minimum)
+ assert expected.maximum == actual.maximum, "expected %r, but maximum is %r"
% (expected, actual.maximum)
+
+
+
class BasicCheckResult(Tuploid):
"""
A basic check result
@@ -120,6 +136,22 @@ class BasicCheckResult(Tuploid):
return 'BasicCheckResult(%r, %r, %r, multiline=%r)' % self.tuple
+def assertBasicCheckResultsEqual(actual, expected):
+ """
+ Compare two BasicCheckResults.
+
+ This gives more helpful output than 'assert actual == expected'
+ """
+ assert isinstance(actual, BasicCheckResult), "not a BasicCheckResult: %r" %
actual
+ assert isinstance(expected, BasicCheckResult), "not a BasicCheckResult: %r"
% expected
+ assert expected.status == actual.status, "expected %r, but status is %r" %
(expected, actual.status)
+ assert expected.infotext == actual.infotext, "expected %r, but infotext is
%r" % (expected, actual.infotext)
+ assert len(expected.perfdata) == len(actual.perfdata), "expected %r, but got %d
perfdata" % (expected, len(actual.perfdata))
+ for pact, pexp in zip(actual.perfdata, expected.perfdata):
+ assertPerfValuesEqual(pact, pexp)
+ assert expected.multiline == actual.multiline, "expected %r, but multiline is
%r" % (expected, actual.multiline)
+
+
class CheckResult(object):
"""
A check result potentially consisting of multiple subresults,
@@ -199,9 +231,7 @@ def assertCheckResultsEqual(actual, expected):
This gives more helpful output than 'assert actual == expected'
"""
if isinstance(actual, BasicCheckResult):
- assert isinstance(expected, BasicCheckResult), \
- "%r is not a BasicCheckResult instance" % expected
- assert actual == expected, "%s != %s" % (actual, expected)
+ assertBasicCheckResultsEqual(actual, expected)
else:
assert isinstance(actual, CheckResult), \
@@ -209,9 +239,9 @@ def assertCheckResultsEqual(actual, expected):
assert isinstance(expected, CheckResult), \
"%r is not a CheckResult instance" % expected
assert len(actual.subresults) == len(expected.subresults), \
- "subresults not of equal length"
+ "subresults not of equal length (expected %d)" %
len(expected.subresults)
for suba, sube in zip(actual.subresults, expected.subresults):
- assert suba == sube, "%r != %r" % (suba, sube)
+ assertBasicCheckResultsEqual(suba, sube)
class DiscoveryEntry(Tuploid):