Module: check_mk
Branch: master
Commit: 8fa2d4104172d7ace6972d2409b393655f4d97d9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8fa2d4104172d7…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Fri Jan 19 12:55:44 2018 +0100
checktestlib: Extract tuple representation logic to base class, make it also available to
BasicCheckResult
Change-Id: Iabbfc8603641d91c438e43409577c4057c0f3463
---
tests/checks/checktestlib.py | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/tests/checks/checktestlib.py b/tests/checks/checktestlib.py
index 6115725..6ab4f8d 100644
--- a/tests/checks/checktestlib.py
+++ b/tests/checks/checktestlib.py
@@ -1,6 +1,23 @@
import types
-class PerfValue(object):
+class Tuploid(object):
+ """Base class for values with variadic tuple
representations"""
+
+ def __eq__(self, other_value):
+ if isinstance(other_value, self.__class__):
+ return all(x==y for x, y in zip(other_value.tuple, self.tuple))
+ elif type(other_value) == 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)
+
+ @property
+ def tuple(self):
+ return (self.key, self.value, self.warn, self.crit, self.minimum, self.maximum)
+
+
+class PerfValue(Tuploid):
"""Represents a single perf value"""
def __init__(self, key, value, warn=None, crit=None, minimum=None, maximum=None):
@@ -27,21 +44,8 @@ class PerfValue(object):
assert type(maximum) in [int, float, types.NoneType]
self.maximum = maximum
- def __eq__(self, other_value):
- if isinstance(other_value, self.__class__):
- return all(x==y for x, y in zip(other_value.tuple, self.tuple))
- elif type(other_value) == 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)
-
- @property
- def tuple(self):
- return (self.key, self.value, self.warn, self.crit, self.minimum, self.maximum)
-
-class BasicCheckResult(object):
+class BasicCheckResult(Tuploid):
"""
A basic check result