Change in vdsm[master]: tests: backport assertAlmostEqual
fromani at redhat.com
fromani at redhat.com
Fri Nov 14 11:25:45 UTC 2014
Francesco Romani has uploaded a new change for review.
Change subject: tests: backport assertAlmostEqual
......................................................................
tests: backport assertAlmostEqual
vm migration tests depend on the 'delta'
keyword argument of the assertAlmostEqual method.
This patch adds the backport of this method,
thus unbreaking the tests on python 2.6.
Change-Id: I5fecc424fec13b01b4a9cdb81f576edb9887c3d3
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/testlib.py
1 file changed, 41 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/56/35156/1
diff --git a/tests/testlib.py b/tests/testlib.py
index 6fffb3c..553bd8c 100644
--- a/tests/testlib.py
+++ b/tests/testlib.py
@@ -200,6 +200,47 @@
safe_repr(container))
raise self.failureException(msg)
+ # FIXME: This is a forward port of the assertNotIn from python
+ # 2.7, remove when no loger supporting earlier versions
+ # we need the 'delta' keyword argument, which was added in python 2.7
+ def assertAlmostEqual(self, first, second, places=None,
+ msg=None, delta=None):
+ """Fail if the two objects are unequal as determined by their
+ difference rounded to the given number of decimal places
+ (default 7) and comparing to zero, or by comparing that the
+ between the two objects is more than the given delta.
+
+ Note that decimal places (from zero) are usually not the same
+ as significant digits (measured from the most signficant digit).
+
+ If the two objects compare equal then they will automatically
+ compare almost equal.
+ """
+ if first == second:
+ # shortcut
+ return
+ if delta is not None and places is not None:
+ raise TypeError("specify delta or places not both")
+
+ if delta is not None:
+ if abs(first - second) <= delta:
+ return
+
+ standardMsg = '%s != %s within %s delta' % (safe_repr(first),
+ safe_repr(second),
+ safe_repr(delta))
+ else:
+ if places is None:
+ places = 7
+
+ if round(abs(second-first), places) == 0:
+ return
+
+ standardMsg = '%s != %s within %r places' % (
+ safe_repr(first), safe_repr(second), places)
+ msg = self._formatMessage(msg, standardMsg)
+ raise self.failureException(msg)
+
class VdsmTestResult(result.TextTestResult):
def __init__(self, *args, **kwargs):
--
To view, visit http://gerrit.ovirt.org/35156
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5fecc424fec13b01b4a9cdb81f576edb9887c3d3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
More information about the vdsm-patches
mailing list