Merge branch '0.10' into 0.11

pull/1867/head
sebres 2017-08-16 21:26:00 +02:00
commit fdcd847f4a
2 changed files with 8 additions and 8 deletions

View File

@ -231,4 +231,4 @@ class StatusExtendedCymruInfo(unittest.TestCase):
self.assertSortedEqual(cymru_info, self.assertSortedEqual(cymru_info,
{"asn": ["nxdomain", "3356",], {"asn": ["nxdomain", "3356",],
"country": ["nxdomain", "US"], "country": ["nxdomain", "US"],
"rir": ["nxdomain", "arin"]}) "rir": ["nxdomain", "arin"]}, level=-1, key=str)

View File

@ -499,7 +499,7 @@ if not hasattr(unittest.TestCase, 'assertDictEqual'):
self.fail(msg) self.fail(msg)
unittest.TestCase.assertDictEqual = assertDictEqual unittest.TestCase.assertDictEqual = assertDictEqual
def assertSortedEqual(self, a, b, level=1, nestedOnly=True, msg=None): def assertSortedEqual(self, a, b, level=1, nestedOnly=True, key=repr, msg=None):
"""Compare complex elements (like dict, list or tuple) in sorted order until """Compare complex elements (like dict, list or tuple) in sorted order until
level 0 not reached (initial level = -1 meant all levels), level 0 not reached (initial level = -1 meant all levels),
or if nestedOnly set to True and some of the objects still contains nested lists or dicts. or if nestedOnly set to True and some of the objects still contains nested lists or dicts.
@ -510,7 +510,7 @@ def assertSortedEqual(self, a, b, level=1, nestedOnly=True, msg=None):
return any(isinstance(v, (dict, list, tuple)) for v in v.itervalues()) return any(isinstance(v, (dict, list, tuple)) for v in v.itervalues())
return any(isinstance(v, (dict, list, tuple)) for v in v) return any(isinstance(v, (dict, list, tuple)) for v in v)
# level comparison routine: # level comparison routine:
def _assertSortedEqual(a, b, level, nestedOnly): def _assertSortedEqual(a, b, level, nestedOnly, key):
# first the lengths: # first the lengths:
if len(a) != len(b): if len(a) != len(b):
raise ValueError('%r != %r' % (a, b)) raise ValueError('%r != %r' % (a, b))
@ -523,20 +523,20 @@ def assertSortedEqual(self, a, b, level=1, nestedOnly=True, msg=None):
for k, v1 in a.iteritems(): for k, v1 in a.iteritems():
v2 = b[k] v2 = b[k]
if isinstance(v1, (dict, list, tuple)) and isinstance(v2, (dict, list, tuple)): if isinstance(v1, (dict, list, tuple)) and isinstance(v2, (dict, list, tuple)):
_assertSortedEqual(v1, v2, level-1 if level != 0 else 0, nestedOnly) _assertSortedEqual(v1, v2, level-1 if level != 0 else 0, nestedOnly, key)
elif v1 != v2: elif v1 != v2:
raise ValueError('%r != %r' % (a, b)) raise ValueError('%r != %r' % (a, b))
else: # list, tuple, something iterable: else: # list, tuple, something iterable:
a = sorted(a, key=repr) a = sorted(a, key=key)
b = sorted(b, key=repr) b = sorted(b, key=key)
for v1, v2 in zip(a, b): for v1, v2 in zip(a, b):
if isinstance(v1, (dict, list, tuple)) and isinstance(v2, (dict, list, tuple)): if isinstance(v1, (dict, list, tuple)) and isinstance(v2, (dict, list, tuple)):
_assertSortedEqual(v1, v2, level-1 if level != 0 else 0, nestedOnly) _assertSortedEqual(v1, v2, level-1 if level != 0 else 0, nestedOnly, key)
elif v1 != v2: elif v1 != v2:
raise ValueError('%r != %r' % (a, b)) raise ValueError('%r != %r' % (a, b))
# compare and produce assertion-error by exception: # compare and produce assertion-error by exception:
try: try:
_assertSortedEqual(a, b, level, nestedOnly) _assertSortedEqual(a, b, level, nestedOnly, key)
except Exception as e: except Exception as e:
standardMsg = e.args[0] if isinstance(e, ValueError) else (str(e) + "\nwithin:") standardMsg = e.args[0] if isinstance(e, ValueError) else (str(e) + "\nwithin:")
diff = ('\n' + '\n'.join(difflib.ndiff( diff = ('\n' + '\n'.join(difflib.ndiff(