This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "SQLObject development repository".
The branch, master has been updated
via c27eead21bc8db3a923515568738b51e0d5f7adc (commit)
via cc83a31214ce42bc9c43e9db8c3cc3c516535b23 (commit)
via a89bdbc2ca38fb6afdda40c93679f4e738fb40e7 (commit)
via 0a3a107b74929d92e86f8cda0084c0373689af1d (commit)
via 80c679f93ac0a4af362a63f4ecbae11aa1b0abbe (commit)
from bc89f66a64b910f0cb99a840ce804d458bcdddcc (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://sourceforge.net/p/sqlobject/sqlobject/ci/c27eead21bc8db3a923515568738b51e0d5f7adc
commit c27eead21bc8db3a923515568738b51e0d5f7adc
Merge: bc89f66 cc83a31
Author: Oleg Broytman <ph...@ph...>
Date: Tue Feb 24 21:52:48 2015 +0300
Merge pull request #96 from drnlm/cmp_rewrite
Cmp rewrite
http://sourceforge.net/p/sqlobject/sqlobject/ci/cc83a31214ce42bc9c43e9db8c3cc3c516535b23
commit cc83a31214ce42bc9c43e9db8c3cc3c516535b23
Author: Neil <drn...@gm...>
Date: Tue Feb 24 16:26:22 2015 +0200
Rename the class to make py.test happy (or why I should run the full test suite more often)
diff --git a/sqlobject/tests/test_complex_sorting.py b/sqlobject/tests/test_complex_sorting.py
index 691f6bd..387fd6b 100644
--- a/sqlobject/tests/test_complex_sorting.py
+++ b/sqlobject/tests/test_complex_sorting.py
@@ -4,7 +4,7 @@ from sqlobject.tests.dbtest import *
# Test more complex orderBy clauses
-class Names(SQLObject):
+class ComplexNames(SQLObject):
class sqlmeta(sqlmeta):
table = 'names_table'
@@ -16,13 +16,13 @@ class Names(SQLObject):
age = IntCol()
-def setupNames():
- setupClass(Names)
- inserts(Names, [('aj', 'baker', '555-444-333', 34),
- ('joe', 'robbins', '444-555-333', 34),
- ('tim', 'jackson', '555-444-222', 32),
- ('joe', 'baker', '222-111-000', 24),
- ('zoe', 'robbins', '444-555-333', 46)],
+def setupComplexNames():
+ setupClass(ComplexNames)
+ inserts(ComplexNames, [('aj', 'baker', '555-444-333', 34),
+ ('joe', 'robbins', '444-555-333', 34),
+ ('tim', 'jackson', '555-444-222', 32),
+ ('joe', 'baker', '222-111-000', 24),
+ ('zoe', 'robbins', '444-555-333', 46)],
schema='firstName lastName phone age')
@@ -37,38 +37,41 @@ def firstList(names):
return [n.firstName for n in names]
-def test_defaultOrder():
- setupNames()
- assert nameList(Names.select()) == \
+def test_defaultComplexOrder():
+ setupComplexNames()
+ assert nameList(ComplexNames.select()) == \
['aj baker', 'joe baker',
'tim jackson', 'joe robbins',
'zoe robbins']
def test_complexOrders():
- setupNames()
- assert nameList(Names.select().orderBy(['age', 'phone',
- 'firstName', 'lastName'])) == \
+ setupComplexNames()
+ assert nameList(ComplexNames.select().orderBy(['age', 'phone',
+ 'firstName',
+ 'lastName'])) == \
['joe baker', 'tim jackson',
'joe robbins', 'aj baker',
'zoe robbins']
- assert nameList(Names.select().orderBy(['-age', 'phone',
- 'firstName', 'lastName'])) == \
+ assert nameList(ComplexNames.select().orderBy(['-age', 'phone',
+ 'firstName',
+ 'lastName'])) == \
['zoe robbins', 'joe robbins',
'aj baker', 'tim jackson',
'joe baker']
- assert nameList(Names.select().orderBy(['age', '-phone',
- 'firstName', 'lastName'])) == \
+ assert nameList(ComplexNames.select().orderBy(['age', '-phone',
+ 'firstName',
+ 'lastName'])) == \
['joe baker', 'tim jackson',
'aj baker', 'joe robbins',
'zoe robbins']
- assert nameList(Names.select().orderBy(['-firstName', 'phone',
- 'lastName', 'age'])) == \
+ assert nameList(ComplexNames.select().orderBy(['-firstName', 'phone',
+ 'lastName', 'age'])) == \
['zoe robbins', 'tim jackson',
'joe baker', 'joe robbins',
'aj baker']
- assert nameList(Names.select().orderBy(['-firstName', '-phone',
- 'lastName', 'age'])) == \
+ assert nameList(ComplexNames.select().orderBy(['-firstName', '-phone',
+ 'lastName', 'age'])) == \
['zoe robbins', 'tim jackson',
'joe robbins', 'joe baker',
'aj baker']
http://sourceforge.net/p/sqlobject/sqlobject/ci/a89bdbc2ca38fb6afdda40c93679f4e738fb40e7
commit a89bdbc2ca38fb6afdda40c93679f4e738fb40e7
Author: Neil <drn...@gm...>
Date: Tue Feb 24 16:04:54 2015 +0200
Fix flake8 error
diff --git a/sqlobject/tests/test_complex_sorting.py b/sqlobject/tests/test_complex_sorting.py
index a93e52f..691f6bd 100644
--- a/sqlobject/tests/test_complex_sorting.py
+++ b/sqlobject/tests/test_complex_sorting.py
@@ -3,6 +3,7 @@ from sqlobject.tests.dbtest import *
# Test more complex orderBy clauses
+
class Names(SQLObject):
class sqlmeta(sqlmeta):
http://sourceforge.net/p/sqlobject/sqlobject/ci/0a3a107b74929d92e86f8cda0084c0373689af1d
commit 0a3a107b74929d92e86f8cda0084c0373689af1d
Author: Neil <drn...@gm...>
Date: Tue Feb 24 16:00:50 2015 +0200
Extra sorting test case
diff --git a/sqlobject/tests/test_complex_sorting.py b/sqlobject/tests/test_complex_sorting.py
new file mode 100644
index 0000000..a93e52f
--- /dev/null
+++ b/sqlobject/tests/test_complex_sorting.py
@@ -0,0 +1,73 @@
+from sqlobject import *
+from sqlobject.tests.dbtest import *
+
+# Test more complex orderBy clauses
+
+class Names(SQLObject):
+
+ class sqlmeta(sqlmeta):
+ table = 'names_table'
+ defaultOrder = ['lastName', 'firstName', 'phone', 'age']
+
+ firstName = StringCol(length=30)
+ lastName = StringCol(length=30)
+ phone = StringCol(length=11)
+ age = IntCol()
+
+
+def setupNames():
+ setupClass(Names)
+ inserts(Names, [('aj', 'baker', '555-444-333', 34),
+ ('joe', 'robbins', '444-555-333', 34),
+ ('tim', 'jackson', '555-444-222', 32),
+ ('joe', 'baker', '222-111-000', 24),
+ ('zoe', 'robbins', '444-555-333', 46)],
+ schema='firstName lastName phone age')
+
+
+def nameList(names):
+ result = []
+ for name in names:
+ result.append('%s %s' % (name.firstName, name.lastName))
+ return result
+
+
+def firstList(names):
+ return [n.firstName for n in names]
+
+
+def test_defaultOrder():
+ setupNames()
+ assert nameList(Names.select()) == \
+ ['aj baker', 'joe baker',
+ 'tim jackson', 'joe robbins',
+ 'zoe robbins']
+
+
+def test_complexOrders():
+ setupNames()
+ assert nameList(Names.select().orderBy(['age', 'phone',
+ 'firstName', 'lastName'])) == \
+ ['joe baker', 'tim jackson',
+ 'joe robbins', 'aj baker',
+ 'zoe robbins']
+ assert nameList(Names.select().orderBy(['-age', 'phone',
+ 'firstName', 'lastName'])) == \
+ ['zoe robbins', 'joe robbins',
+ 'aj baker', 'tim jackson',
+ 'joe baker']
+ assert nameList(Names.select().orderBy(['age', '-phone',
+ 'firstName', 'lastName'])) == \
+ ['joe baker', 'tim jackson',
+ 'aj baker', 'joe robbins',
+ 'zoe robbins']
+ assert nameList(Names.select().orderBy(['-firstName', 'phone',
+ 'lastName', 'age'])) == \
+ ['zoe robbins', 'tim jackson',
+ 'joe baker', 'joe robbins',
+ 'aj baker']
+ assert nameList(Names.select().orderBy(['-firstName', '-phone',
+ 'lastName', 'age'])) == \
+ ['zoe robbins', 'tim jackson',
+ 'joe robbins', 'joe baker',
+ 'aj baker']
http://sourceforge.net/p/sqlobject/sqlobject/ci/80c679f93ac0a4af362a63f4ecbae11aa1b0abbe
commit 80c679f93ac0a4af362a63f4ecbae11aa1b0abbe
Author: Neil <drn...@gm...>
Date: Fri Feb 13 11:08:10 2015 +0200
rewrite orderby to avoid cmp
diff --git a/sqlobject/joins.py b/sqlobject/joins.py
index 17ae613..675beb7 100644
--- a/sqlobject/joins.py
+++ b/sqlobject/joins.py
@@ -96,19 +96,48 @@ class SOJoin(object):
def _applyOrderBy(self, results, defaultSortClass):
if self.orderBy is not None:
- results.sort(sorter(self.orderBy))
+ doSort(results, self.orderBy)
return results
-def sorter(orderBy):
+class MinType(object):
+ """Sort less than everything, for handling None's in the results"""
+ # functools.total_ordering would simplify this, but isn't available
+ # for python 2.6
+
+ def __lt__(self, other):
+ if self is other:
+ return False
+ return True
+
+ def __eq__(self, other):
+ return self is other
+
+ def __gt__(self, other):
+ return False
+
+ def __le__(self, other):
+ return True
+
+ def __ge__(self, other):
+ if self is other:
+ return True
+ return False
+
+
+Min = MinType()
+
+
+def doSort(results, orderBy):
if isinstance(orderBy, (tuple, list)):
if len(orderBy) == 1:
orderBy = orderBy[0]
else:
- fhead = sorter(orderBy[0])
- frest = sorter(orderBy[1:])
- return lambda a, b, fhead=fhead, frest=frest: \
- fhead(a, b) or frest(a, b)
+ # Rely on stable sort results, since this is simpler
+ # than trying to munge everything into a single sort key
+ doSort(results, orderBy[0])
+ doSort(results, orderBy[1:])
+ return
if isinstance(orderBy, sqlbuilder.DESC) \
and isinstance(orderBy.expr, sqlbuilder.SQLObjectField):
orderBy = '-' + orderBy.expr.original
@@ -121,19 +150,12 @@ def sorter(orderBy):
else:
reverse = False
- def cmper(a, b, attr=orderBy, rev=reverse):
- a = getattr(a, attr)
- b = getattr(b, attr)
- if rev:
- a, b = b, a
+ def sortkey(x, attr=orderBy):
+ a = getattr(x, attr)
if a is None:
- if b is None:
- return 0
- return -1
- if b is None:
- return 1
- return cmp(a, b)
- return cmper
+ return Min
+ return a
+ results.sort(key=sortkey, reverse=reverse)
# This is a one-to-many
-----------------------------------------------------------------------
Summary of changes:
sqlobject/joins.py | 58 ++++++++++++++++-------
sqlobject/tests/test_complex_sorting.py | 77 +++++++++++++++++++++++++++++++
2 files changed, 117 insertions(+), 18 deletions(-)
create mode 100644 sqlobject/tests/test_complex_sorting.py
hooks/post-receive
--
SQLObject development repository
|