| 13 | |
| 14 | |
| 15 | def compare_dict(dict1, dict2, equivalent=True, msg="", tol=10e-8): |
| 16 | for key in dict1: |
| 17 | if key not in dict2: |
| 18 | return ( |
| 19 | False, |
| 20 | "{0} should be {1}".format(list(dict1.keys()), list(dict2.keys())), |
| 21 | ) |
| 22 | for key in dict1: |
| 23 | if isinstance(dict1[key], dict): |
| 24 | equivalent, msg = compare_dict(dict1[key], dict2[key], tol=tol) |
| 25 | elif isinstance(dict1[key], Num) and isinstance(dict2[key], Num): |
| 26 | if not comp_nums(dict1[key], dict2[key], tol): |
| 27 | return ( |
| 28 | False, |
| 29 | "['{0}'] = {1} should be {2}".format(key, dict1[key], dict2[key]), |
| 30 | ) |
| 31 | elif is_num_list(dict1[key]) and is_num_list(dict2[key]): |
| 32 | if not comp_num_list(dict1[key], dict2[key], tol): |
| 33 | return ( |
| 34 | False, |
| 35 | "['{0}'] = {1} should be {2}".format(key, dict1[key], dict2[key]), |
| 36 | ) |
| 37 | elif not (dict1[key] == dict2[key]): |
| 38 | return ( |
| 39 | False, |
| 40 | "['{0}'] = {1} should be {2}".format(key, dict1[key], dict2[key]), |
| 41 | ) |
| 42 | if not equivalent: |
| 43 | return False, "['{0}']".format(key) + msg |
| 44 | return equivalent, msg |
| 45 | |
| 46 | |
| 47 | def strip_dict_params(d1, d2, ignore=["uid"]): |