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