[master 14/22] edd: Make our own assertListEqual to get rid of truncated output.
vathpela
installerbot-noreply at redhat.com
Wed Oct 28 15:55:14 UTC 2015
From: Peter Jones <pjones at redhat.com>
It's really annoying that there's no way to turn off
unittest.assertEqual()'s stupid string truncation, and it makes it very
difficult to debug test failures that involve a fairly large amount of
data. So replace it with something that tells us the meaningful bits.
Signed-off-by: Peter Jones <pjones at redhat.com>
---
tests/devicelibs_test/edd_test.py | 64 ++++++++++++++++++++++++++++++++++-----
1 file changed, 57 insertions(+), 7 deletions(-)
diff --git a/tests/devicelibs_test/edd_test.py b/tests/devicelibs_test/edd_test.py
index 27dca11..7f03fab 100644
--- a/tests/devicelibs_test/edd_test.py
+++ b/tests/devicelibs_test/edd_test.py
@@ -4,6 +4,7 @@
import inspect
import logging
import copy
+import pprint
from blivet.devicelibs import edd
@@ -34,8 +35,11 @@ def __eq__(self, other):
return self.__dict__ == other.__dict__
class EddTestCase(unittest.TestCase):
- _edd_logger = None
- maxDiff = None
+ def __init__(self, *args, **kwds):
+ super(EddTestCase, self).__init__(*args, **kwds)
+ self._edd_logger = None
+ self.maxDiff = None
+ self.longMessage = True
def setUp(self):
super(EddTestCase, self).setUp()
@@ -79,14 +83,60 @@ def tearDown(self):
edd.testdata_log.removeHandler(self.td_log_handler)
super(EddTestCase, self).tearDown()
+ def assertListEqual(self, left, right, msg=None):
+ left.sort()
+ right.sort()
+
+ found = []
+ rightmissing = []
+ leftmissing = []
+ for x in left:
+ if x in right:
+ found.append(x)
+ else:
+ rightmissing.append(x)
+ for x in right:
+ if x not in found:
+ leftmissing.append(x)
+ if msg:
+ raise AssertionError(msg)
+
+ s = "\n"
+ if leftmissing:
+ s += "log has: \n"
+ for l in leftmissing:
+ s += " %s\n" % (pprint.pformat(l),)
+
+ if rightmissing:
+ s += "expected: \n"
+ for r in rightmissing:
+ s += " %s\n" % (pprint.pformat(r),)
+
+ if leftmissing or rightmissing:
+ raise AssertionError(s)
+
+ def assertEqual(self, left, right, msg=None):
+ if left != right:
+ l = len(left)
+ r = len(right)
+ for x in range(0, max(l, r)):
+ if x > l-1:
+ self.assertEqual(None, right[x], msg)
+ if x > r-1:
+ self.assertEqual(left[x], None, msg)
+ if left[x] != right[x]:
+ if msg:
+ raise AssertionError(msg)
+ else:
+ raise AssertionError("%s != %s" % (
+ pprint.pformat(left), pprint.pformat(right)))
+
def checkLogs(self, debugs=None, infos=None, warnings=None, errors=None):
def check(left, right_object):
- left = [mock.call(*x) for x in left or []]
- left.sort()
+ newleft = [mock.call(*x) for x in left or []]
right = copy.copy(right_object.call_args_list or [])
- right.sort()
- self.assertEqual(left, right)
- if len(left) == 0:
+ self.assertListEqual(newleft, right)
+ if len(newleft) == 0:
self.assertEqual(right_object.called, False)
else:
self.assertEqual(right_object.called, True)
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/08270a48476ca776eafdbdbabaea586a4c166d51
More information about the anaconda-patches
mailing list