Changeset 12428 for main/waeup.ikoba


Ignore:
Timestamp:
8 Jan 2015, 14:48:29 (10 years ago)
Author:
Henrik Bettermann
Message:

Add Uli's modifications r12425 - r12427 also in waeup.ikoba.

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  
    3232    IkobaObjectWidget, IkobaObjectDisplayWidget
    3333    )
     34
     35#: A unique default value.
     36DEFAULT_VALUE = object()
    3437
    3538
     
    7881
    7982    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        """
    8286        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
    8699
    87100    def to_string(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/products/tests/test_productoptions.py

    r12343 r12428  
    8686        return
    8787
     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
    88112class ProductOptionFieldTests(unittest.TestCase):
    89113
Note: See TracChangeset for help on using the changeset viewer.