From dcfcaa9b682cba3f5abc10c177869f2b8b40386f Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 10 Mar 2003 00:22:52 +0000 Subject: [PATCH] fix to sf bug 691071, really this time git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1581 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/backends/back_anydbm.py | 16 ++++++++++------ roundup/date.py | 5 ++--- test/test_dates.py | 9 +++++++-- test/test_db.py | 21 ++++++++++++++++----- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index 417e3d2..2607654 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.110 2003-03-08 20:41:45 kedder Exp $ +#$Id: back_anydbm.py,v 1.111 2003-03-10 00:22:20 richard Exp $ ''' This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python @@ -1813,15 +1813,19 @@ class Class(hyperdb.Class): # Compare contents of multilink property if lenghts is # equal r = cmp ('.'.join(av), '.'.join(bv)) - if dir == '+': - return r - elif dir == '-': - return -r - elif isinstance(propclass, Number) or isinstance(propclass, Boolean): + if r: + if dir == '+': + return r + else: + return -r + + else: + # all other types just compare if dir == '+': r = cmp(av, bv) elif dir == '-': r = cmp(bv, av) + if r != 0: return r # end for dir, prop in sort, group: # if all else fails, compare the ids diff --git a/roundup/date.py b/roundup/date.py index 3e6559f..c214cd1 100644 --- a/roundup/date.py +++ b/roundup/date.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: date.py,v 1.46 2003-03-08 20:41:45 kedder Exp $ +# $Id: date.py,v 1.47 2003-03-10 00:22:20 richard Exp $ __doc__ = """ Date, time and time interval handling. @@ -354,10 +354,9 @@ class Interval: def __cmp__(self, other): """Compare this interval to another interval.""" if other is None: + # we are always larger than None return 1 for attr in 'sign year month day hour minute second'.split(): - if not hasattr(other, attr): - return 1 r = cmp(getattr(self, attr), getattr(other, attr)) if r: return r diff --git a/test/test_dates.py b/test/test_dates.py index 2223e3e..fc0c9bd 100644 --- a/test/test_dates.py +++ b/test/test_dates.py @@ -15,11 +15,11 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: test_dates.py,v 1.19 2003-03-06 06:12:30 richard Exp $ +# $Id: test_dates.py,v 1.20 2003-03-10 00:22:21 richard Exp $ import unittest, time -from roundup.date import Date, Interval, fixTimeOverflow +from roundup.date import Date, Interval, Range, fixTimeOverflow class DateTestCase(unittest.TestCase): def testDateInterval(self): @@ -223,6 +223,11 @@ class DateTestCase(unittest.TestCase): l = [i1, i2]; l.sort() ae(l, [i1, i2]) + i1 = Interval("1:20") + i2 = Interval("2d") + i3 = Interval("3:30") + l = [i1, i2, i3]; l.sort() + ae(l, [i1, i3, i2]) def suite(): return unittest.makeSuite(DateTestCase, 'test') diff --git a/test/test_db.py b/test/test_db.py index 7af06e7..a8f35c2 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: test_db.py,v 1.74 2003-03-06 06:03:51 richard Exp $ +# $Id: test_db.py,v 1.75 2003-03-10 00:22:21 richard Exp $ import unittest, os, shutil, time @@ -632,9 +632,12 @@ class anydbmDBTestCase(MyTestCase): self.db.user.create(**user) iss = self.db.issue for issue in ( - {'title': 'issue one', 'status': '2'}, - {'title': 'issue two', 'status': '1'}, - {'title': 'issue three', 'status': '1', 'nosy': ['1','2']}): + {'title': 'issue one', 'status': '2', + 'foo': date.Interval('1:10')}, + {'title': 'issue two', 'status': '1', + 'foo': date.Interval('1d')}, + {'title': 'issue three', 'status': '1', + 'nosy': ['1','2']}): self.db.issue.create(**issue) self.db.commit() return self.assertEqual, self.db.issue.filter @@ -662,8 +665,16 @@ class anydbmDBTestCase(MyTestCase): ae(filt(None, {'nosy': '2', 'status': '1'}, ('+','id'), (None,None)), ['3']) + def testFilteringIntervalSort(self): + ae, filt = self.filteringSetup() + # ascending should sort None, 1:10, 1d + ae(filt(None, {}, ('+','foo'), (None,None)), ['3', '1', '2']) + # descending should sort 1d, 1:10, None + ae(filt(None, {}, ('-','foo'), (None,None)), ['2', '1', '3']) + -# TODO test auditors and reactors +# XXX add sorting tests for other types +# XXX test auditors and reactors class anydbmReadOnlyDBTestCase(MyTestCase): def setUp(self): -- 2.30.2