Skip to content

Commit b96bc09

Browse files
author
Richard Jones
committed
fix to [SF#691071], really this time
1 parent d350dc2 commit b96bc09

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

roundup/backends/back_anydbm.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.110 2003-03-08 20:41:45 kedder Exp $
18+
#$Id: back_anydbm.py,v 1.111 2003-03-10 00:22:20 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -1813,15 +1813,19 @@ def sortfun(a, b, sort=sort, group=group, properties=self.getprops(),
18131813
# Compare contents of multilink property if lenghts is
18141814
# equal
18151815
r = cmp ('.'.join(av), '.'.join(bv))
1816-
if dir == '+':
1817-
return r
1818-
elif dir == '-':
1819-
return -r
1820-
elif isinstance(propclass, Number) or isinstance(propclass, Boolean):
1816+
if r:
1817+
if dir == '+':
1818+
return r
1819+
else:
1820+
return -r
1821+
1822+
else:
1823+
# all other types just compare
18211824
if dir == '+':
18221825
r = cmp(av, bv)
18231826
elif dir == '-':
18241827
r = cmp(bv, av)
1828+
if r != 0: return r
18251829

18261830
# end for dir, prop in sort, group:
18271831
# if all else fails, compare the ids

roundup/date.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: date.py,v 1.46 2003-03-08 20:41:45 kedder Exp $
18+
# $Id: date.py,v 1.47 2003-03-10 00:22:20 richard Exp $
1919

2020
__doc__ = """
2121
Date, time and time interval handling.
@@ -354,10 +354,9 @@ def __init__(self, spec, sign=1):
354354
def __cmp__(self, other):
355355
"""Compare this interval to another interval."""
356356
if other is None:
357+
# we are always larger than None
357358
return 1
358359
for attr in 'sign year month day hour minute second'.split():
359-
if not hasattr(other, attr):
360-
return 1
361360
r = cmp(getattr(self, attr), getattr(other, attr))
362361
if r:
363362
return r

test/test_dates.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_dates.py,v 1.19 2003-03-06 06:12:30 richard Exp $
18+
# $Id: test_dates.py,v 1.20 2003-03-10 00:22:21 richard Exp $
1919

2020
import unittest, time
2121

22-
from roundup.date import Date, Interval, fixTimeOverflow
22+
from roundup.date import Date, Interval, Range, fixTimeOverflow
2323

2424
class DateTestCase(unittest.TestCase):
2525
def testDateInterval(self):
@@ -223,6 +223,11 @@ def testSorting(self):
223223
l = [i1, i2]; l.sort()
224224
ae(l, [i1, i2])
225225

226+
i1 = Interval("1:20")
227+
i2 = Interval("2d")
228+
i3 = Interval("3:30")
229+
l = [i1, i2, i3]; l.sort()
230+
ae(l, [i1, i3, i2])
226231

227232
def suite():
228233
return unittest.makeSuite(DateTestCase, 'test')

test/test_db.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_db.py,v 1.74 2003-03-06 06:03:51 richard Exp $
18+
# $Id: test_db.py,v 1.75 2003-03-10 00:22:21 richard Exp $
1919

2020
import unittest, os, shutil, time
2121

@@ -632,9 +632,12 @@ def filteringSetup(self):
632632
self.db.user.create(**user)
633633
iss = self.db.issue
634634
for issue in (
635-
{'title': 'issue one', 'status': '2'},
636-
{'title': 'issue two', 'status': '1'},
637-
{'title': 'issue three', 'status': '1', 'nosy': ['1','2']}):
635+
{'title': 'issue one', 'status': '2',
636+
'foo': date.Interval('1:10')},
637+
{'title': 'issue two', 'status': '1',
638+
'foo': date.Interval('1d')},
639+
{'title': 'issue three', 'status': '1',
640+
'nosy': ['1','2']}):
638641
self.db.issue.create(**issue)
639642
self.db.commit()
640643
return self.assertEqual, self.db.issue.filter
@@ -662,8 +665,16 @@ def testFilteringMany(self):
662665
ae(filt(None, {'nosy': '2', 'status': '1'}, ('+','id'), (None,None)),
663666
['3'])
664667

668+
def testFilteringIntervalSort(self):
669+
ae, filt = self.filteringSetup()
670+
# ascending should sort None, 1:10, 1d
671+
ae(filt(None, {}, ('+','foo'), (None,None)), ['3', '1', '2'])
672+
# descending should sort 1d, 1:10, None
673+
ae(filt(None, {}, ('-','foo'), (None,None)), ['2', '1', '3'])
674+
665675

666-
# TODO test auditors and reactors
676+
# XXX add sorting tests for other types
677+
# XXX test auditors and reactors
667678

668679
class anydbmReadOnlyDBTestCase(MyTestCase):
669680
def setUp(self):

0 commit comments

Comments
 (0)