Index: lnt/trunk/lnt/external/stats/pstat.py =================================================================== --- lnt/trunk/lnt/external/stats/pstat.py +++ lnt/trunk/lnt/external/stats/pstat.py @@ -953,7 +953,8 @@ def arowcompare(row1, row2): """ Compares two rows from an array, regardless of whether it is an -array of numbers or of python objects (which requires the cmp function). +array of numbers or of python objects (which requires rich comparison +method __eq__). @@@PURPOSE? 2007-11-26 Usage: arowcompare(row1,row2) @@ -962,7 +963,7 @@ """ return if row1.dtype.char=='O' or row2.dtype=='O': - cmpvect = N.logical_not(abs(N.array(list(map(cmp, row1, row2))))) # cmp fcn gives -1,0,1 + cmpvect = N.array([x == y for x, y in zip(row1, row2)]) else: cmpvect = N.equal(row1,row2) return cmpvect @@ -971,7 +972,8 @@ def arowsame(row1, row2): """ Compares two rows from an array, regardless of whether it is an -array of numbers or of python objects (which requires the cmp function). +array of numbers or of python objects (which requires rich comparison +method __eq__). Usage: arowsame(row1,row2) Returns: 1 if the two rows are identical, 0 otherwise. @@ -1021,8 +1023,8 @@ else: # must be an Object array, alltrue/equal functions don't work for item in inarray[1:]: newflag = 1 - for unq in uniques: # NOTE: cmp --> 0=same, -1=<, 1=> - test = N.sum(abs(N.array(list(map(cmp, item, unq))))) + for unq in uniques: + test = N.sum(N.array([x == y for x, y in zip(item, unq)])) if test == 0: # if item identical to any 1 row in uniques newflag = 0 # then not a novel item to add break Index: lnt/trunk/lnt/server/db/testsuitedb.py =================================================================== --- lnt/trunk/lnt/server/db/testsuitedb.py +++ lnt/trunk/lnt/server/db/testsuitedb.py @@ -9,6 +9,7 @@ import datetime import json import os +import itertools import aniso8601 import sqlalchemy @@ -208,8 +209,8 @@ __tablename__ = db_key_name + '_Order' # We guarantee that our fields are stored in the order they are - # supposed to be lexicographically compared, the __cmp__ method - # relies on this. + # supposed to be lexicographically compared, the rich comparison + # methods rely on this. fields = sorted(self.order_fields, key=lambda of: of.ordinal) @@ -274,17 +275,58 @@ def name(self): return self.as_ordered_string() - def __cmp__(self, b): + def _get_comparison_discriminant(self, b): + """Return a representative pair of converted revision from self + and b. Order of the element on this pair is the same as the + order of self relative to b. + """ # SA occasionally uses comparison to check model instances - # verse some sentinels, so we ensure we support comparison + # versus some sentinels, so we ensure we support comparison # against non-instances. if self.__class__ is not b.__class__: - return -1 - # Compare every field in lexicographic order. - return cmp([convert_revision(self.get_field(item), cache=Order.order_name_cache) - for item in self.fields], - [convert_revision(b.get_field(item), cache=Order.order_name_cache) - for item in self.fields]) + return (0, 1) + + # Pair converted revision from self and b. + converted_revisions = map( + lambda item: ( + convert_revision( + self.get_field(item), cache=Order.order_name_cache + ), + convert_revision( + b.get_field(item), cache=Order.order_name_cache + ), + ), + self.fields, + ) + # Return the first unequal pair, or (0, 0) otherwise. + return next( + itertools.dropwhile(lambda x: x[0] == x[1], converted_revisions), + (0, 0), + ) + + def __eq__(self, b): + discriminant = self._get_comparison_discriminant(b) + return discriminant[0] == discriminant[1] + + def __ne__(self, b): + discriminant = self._get_comparison_discriminant(b) + return discriminant[0] != discriminant[1] + + def __lt__(self, b): + discriminant = self._get_comparison_discriminant(b) + return discriminant[0] < discriminant[1] + + def __le__(self, b): + discriminant = self._get_comparison_discriminant(b) + return discriminant[0] <= discriminant[1] + + def __gt__(self, b): + discriminant = self._get_comparison_discriminant(b) + return discriminant[0] > discriminant[1] + + def __ge__(self, b): + discriminant = self._get_comparison_discriminant(b) + return discriminant[0] >= discriminant[1] def __json__(self, include_id=True): result = {} Index: lnt/trunk/tests/server/ui/test_api_modify.py =================================================================== --- lnt/trunk/tests/server/ui/test_api_modify.py +++ lnt/trunk/tests/server/ui/test_api_modify.py @@ -226,5 +226,4 @@ if __name__ == '__main__': - unittest.TestLoader.sortTestMethodsUsing = lambda _, x, y: cmp(x, y) unittest.main(argv=[sys.argv[0], ]) Index: lnt/trunk/tests/server/ui/test_api_roundtrip.py =================================================================== --- lnt/trunk/tests/server/ui/test_api_roundtrip.py +++ lnt/trunk/tests/server/ui/test_api_roundtrip.py @@ -57,5 +57,4 @@ if __name__ == '__main__': - unittest.TestLoader.sortTestMethodsUsing = lambda _, x, y: cmp(x, y) unittest.main(argv=[sys.argv[0], ])