def check_doc_str(self, doc, module_name, func_name, expected, mod=None, extra_args=[], obj_class=None): r = parse_doc_str(doc, module_name, mod, func_name, extra_args, obj_class) # Quick pass if everything matches if r == expected: return msg = "Expected:\n%s\nActual\n%s" % (pformat(expected), pformat(r)) self.assertEqual(len(r), len(expected), msg) def check_dict(e, a, indent): if e == a: return missing_keys = set(e.keys()) - set(a.keys()) extra_keys = set(a.keys()) - set(e.keys()) mismatched_keys = [k for k in set(a.keys()) & set(e.keys()) if a[k] != e[k]] if missing_keys: print("%sDid not received following keys: %s" % (indent, ", ".join(missing_keys))) if extra_keys: print("%sDid not expect following keys: %s" % (indent, ", ".join(extra_keys))) for k in mismatched_keys: if isinstance(e[k], dict) and isinstance(a[k], dict): check_dict(e[k], a[k], indent + " ") elif ( isinstance(e[k], tuple) and isinstance(a[k], tuple) or isinstance(e[k], list) and isinstance(a[k], list) ): check_seq(e[k], a[k], indent + " ") else: print('%sExpected "%s": "%s"' % (indent, k, e[k])) print('%sActual "%s": "%s"' % (indent, k, a[k])) print("") def check_seq(e, a, indent): if e == a: return for i, (e2, a2) in enumerate(zip(e, a)): if isinstance(e2, dict) and isinstance(a2, dict): check_dict(e2, a2, indent + " ") elif isinstance(e2, tuple) and isinstance(a2, tuple) or isinstance(e2, list) and isinstance(a2, list): check_seq(e2, a2, indent + " ") elif e1 != a1: print('%sExpected "%s"' % (indent, e2)) print('%sActual "%s"' % (indent, a2)) print("") for e1, a1 in zip(expected, r): check_dict(e1, a1, "") self.fail(msg)
def check_doc_str(self, doc, module_name, func_name, expected, mod=None, extra_args=[], obj_class=None): r = parse_doc_str(doc, module_name, mod, func_name, extra_args, obj_class) # Quick pass if everything matches if r == expected: return msg = 'Expected:\n%s\nActual\n%s' % (pformat(expected), pformat(r)) self.assertEqual(len(r), len(expected), msg) def check_dict(e, a, indent): if e == a: return missing_keys = set(e.keys()) - set(a.keys()) extra_keys = set(a.keys()) - set(e.keys()) mismatched_keys = [k for k in set(a.keys()) & set(e.keys()) if a[k] != e[k]] if missing_keys: print('%sDid not received following keys: %s' % (indent, ', '.join(missing_keys))) if extra_keys: print('%sDid not expect following keys: %s' % (indent, ', '.join(extra_keys))) for k in mismatched_keys: if isinstance(e[k], dict) and isinstance(a[k], dict): check_dict(e[k], a[k], indent + ' ') elif (isinstance(e[k], tuple) and isinstance(a[k], tuple) or isinstance(e[k], list) and isinstance(a[k], list)): check_seq(e[k], a[k], indent + ' ') else: print('%sExpected "%s": "%s"' % (indent, k, e[k])) print('%sActual "%s": "%s"' % (indent, k, a[k])) print('') def check_seq(e, a, indent): if e == a: return for i, (e2, a2) in enumerate(zip(e, a)): if isinstance(e2, dict) and isinstance(a2, dict): check_dict(e2, a2, indent + ' ') elif (isinstance(e2, tuple) and isinstance(a2, tuple) or isinstance(e2, list) and isinstance(a2, list)): check_seq(e2, a2, indent + ' ') elif e1 != a1: print('%sExpected "%s"' % (indent, e2)) print('%sActual "%s"' % (indent, a2)) print('') for e1, a1 in zip(expected, r): check_dict(e1, a1, '') self.fail(msg)