Changeset 12428 for main/waeup.ikoba/trunk
- Timestamp:
- 8 Jan 2015, 14:48:29 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba/products
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/products/productoptions.py
r12419 r12428 32 32 IkobaObjectWidget, IkobaObjectDisplayWidget 33 33 ) 34 35 #: A unique default value. 36 DEFAULT_VALUE = object() 34 37 35 38 … … 78 81 79 82 def __eq__(self, obj): 80 default = object() 81 result = [] 83 """Two ProductOption objects are equal if their `title`, `fee` and 84 `grade` are equal. 85 """ 82 86 for name in ('title', 'fee', 'currency',): 83 result.append( 84 getattr(self, name) == getattr(obj, name, default)) 85 return False not in result 87 if getattr(self, name) != getattr(obj, name, DEFAULT_VALUE): 88 return False 89 return True 90 91 def __ne__(self, other): 92 """Two ProductOptions are not equal, if their equality test fails. 93 94 a != b <-> not(a == b). Python doc tell, that __ne__ should 95 also be provided, whenever __eq__ is implemented. 96 """ 97 return not self.__eq__(other) 98 86 99 87 100 def to_string(self): -
main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_productoptions.py
r12343 r12428 86 86 return 87 87 88 def test_eq(self): 89 # we can compare equality of ProductOption objects 90 item1 = ProductOption(self.valid_title, self.valid_fee, self.valid_currency) 91 item2 = ProductOption(self.valid_title, self.valid_fee, self.valid_currency) 92 item3 = ProductOption() 93 item4 = ProductOption() 94 assert item1 is not item2 95 assert item1 == item1 96 assert item1 == item2 97 assert item3 is not item4 98 assert item3 == item4 99 assert item1.__eq__(item2) is True 100 assert item1.__eq__(item3) is False 101 102 def test_ne(self): 103 # we can also tell, which ResultEntries are _not_ equal 104 item1 = ProductOption(self.valid_title, self.valid_fee, self.valid_currency) 105 item2 = ProductOption() 106 assert item1 != item2 107 assert item1.__ne__(item2) is True 108 assert item1.__ne__(item1) is False 109 110 111 88 112 class ProductOptionFieldTests(unittest.TestCase): 89 113
Note: See TracChangeset for help on using the changeset viewer.