1
1
import json
2
2
3
- from candore .modules .variations import Variations , Constants
4
- from candore .utils import last_index_of_element , is_list_contains_dict
3
+ from candore .modules .variations import Constants
4
+ from candore .modules .variations import Variations
5
+ from candore .utils import is_list_contains_dict
6
+ from candore .utils import last_index_of_element
5
7
6
8
7
9
class Comparator :
@@ -29,7 +31,10 @@ def record_variation(self, pre, post, var_details=None):
29
31
big_key = [str (itm ) for itm in self .big_key ]
30
32
full_path = "/" .join (big_key )
31
33
var_full_path = "/" .join ([itm for itm in self .big_key if not isinstance (itm , int )])
32
- if var_full_path in self .variations .expected_variations or var_full_path in self .variations .skipped_variations :
34
+ if (
35
+ var_full_path in self .variations .expected_variations
36
+ or var_full_path in self .variations .skipped_variations
37
+ ):
33
38
if self .record_evs :
34
39
variation = {
35
40
"pre" : pre ,
@@ -48,7 +53,10 @@ def record_constants(self, pre, post, var_details=None):
48
53
big_key = [str (itm ) for itm in self .big_key ]
49
54
full_path = "/" .join (big_key )
50
55
var_full_path = "/" .join ([itm for itm in self .big_key if not isinstance (itm , int )])
51
- if var_full_path in self .constants .expected_constants or var_full_path in self .constants .skipped_constants :
56
+ if (
57
+ var_full_path in self .constants .expected_constants
58
+ or var_full_path in self .constants .skipped_constants
59
+ ):
52
60
if self .record_evs :
53
61
variation = {
54
62
"pre" : pre ,
@@ -93,19 +101,22 @@ def _is_data_type_list_contains_dict(self, pre, post):
93
101
self .compare_all_pres_with_posts (
94
102
pre_entity , post_entity , unique_key = pre_entity ["id" ]
95
103
)
104
+ post .remove (post_entity )
105
+ break
96
106
else :
97
107
key = list (pre_entity .keys ())[0 ]
98
- if pre_entity [key ] == post_entity [ key ] :
108
+ if pre_entity [key ] == post_entity . get ( key ) :
99
109
self .compare_all_pres_with_posts (
100
110
pre_entity [key ], post_entity [key ], unique_key = key
101
111
)
112
+ del post_entity [key ]
113
+ break
102
114
if "id" in pre_entity :
103
115
self .remove_path (pre_entity ["id" ])
104
116
else :
105
117
self .remove_path (pre_entity [list (pre_entity .keys ())[0 ]])
106
118
107
119
def _is_data_type_list (self , pre , post , unique_key = "" ):
108
-
109
120
def custom_key (elem ):
110
121
return 'None' if elem is None else str (elem )
111
122
@@ -121,9 +132,9 @@ def custom_key(elem):
121
132
def compare_all_pres_with_posts (self , pre_data , post_data , unique_key = "" , var_details = None ):
122
133
if unique_key :
123
134
self .big_key .append (unique_key )
124
- if type (pre_data ) is dict :
135
+ if isinstance (pre_data , dict ) :
125
136
self ._is_data_type_dict (pre_data , post_data , unique_key = unique_key )
126
- elif type (pre_data ) is list :
137
+ elif isinstance (pre_data , list ) :
127
138
self ._is_data_type_list (pre_data , post_data , unique_key = unique_key )
128
139
else :
129
140
if pre_data != post_data :
0 commit comments