client-barcode: Implement (in)equality test for class Item

This commit is contained in:
Sebastian Pipping 2011-10-10 21:55:44 +02:00
parent 4f6ae55ba4
commit 92efe05fed
1 changed files with 19 additions and 0 deletions

View File

@ -12,3 +12,22 @@ class Item:
self.id = int(d['id']) self.id = int(d['id'])
self.name = d['name'] self.name = d['name']
self.price = Decimal(d['price']) self.price = Decimal(d['price'])
def __eq__(self, other):
for key in ('deposit', 'id', 'name', 'price'):
if getattr(self, key) != getattr(other, key):
return False
return True
def __ne__(self, other):
return not self.__eq__(other)
if __name__ == '__main__':
import copy
d1 = {'deposit':'0.20', 'id':'15', 'name':'foo bar', 'price':'1.40'}
d2 = copy.copy(d1)
a = Item(d1)
b = Item(d2)
print(a == b)
print(a != b)