File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -213,11 +213,19 @@ def __getstate__(self):
213
213
def __setstate__ (self , d ):
214
214
self .__dict__ .update (d )
215
215
216
- def __hash__ (self ):
216
+ def __key__ (self ):
217
217
if hasattr (self , "id" ):
218
- return hash (( self .endpoint .name , self .id ) )
218
+ return ( self .endpoint .name , self .id )
219
219
else :
220
- return hash (self .endpoint .name )
220
+ return (self .endpoint .name )
221
+
222
+ def __hash__ (self ):
223
+ return hash (self .__key__ ())
224
+
225
+ def __eq__ (self , other ):
226
+ if isinstance (other , Record ):
227
+ return self .__key__ () == other .__key__ ()
228
+ return NotImplemented
221
229
222
230
def _add_cache (self , item ):
223
231
key , value = item
Original file line number Diff line number Diff line change @@ -128,3 +128,14 @@ def test_hash_diff(self):
128
128
test2 = Record ({}, None , endpoint2 )
129
129
test2 .id = 2
130
130
self .assertNotEqual (hash (test1 ), hash (test2 ))
131
+
132
+ def test_compare (self ):
133
+ endpoint1 = Mock ()
134
+ endpoint1 .name = "test-endpoint"
135
+ endpoint2 = Mock ()
136
+ endpoint2 .name = "test-endpoint"
137
+ test1 = Record ({}, None , endpoint1 )
138
+ test1 .id = 1
139
+ test2 = Record ({}, None , endpoint2 )
140
+ test2 .id = 1
141
+ self .assertEqual (test1 , test2 )
You can’t perform that action at this time.
0 commit comments