Merge lp:~jkakar/storm/sqlobject-is-empty into lp:storm

Proposed by Jamu Kakar
Status: Merged
Approved by: Jamu Kakar
Approved revision: 365
Merged at revision: 366
Proposed branch: lp:~jkakar/storm/sqlobject-is-empty
Merge into: lp:storm
Diff against target: 65 lines (+27/-1)
3 files modified
storm/sqlobject.py (+10/-0)
storm/store.py (+1/-1)
tests/sqlobject.py (+16/-0)
To merge this branch: bzr merge lp:~jkakar/storm/sqlobject-is-empty
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Stuart Bishop (community) Approve
Storm Developers Pending
Review via email: mp+31565@code.launchpad.net

Description of the change

This branch introduces the following changes:

- SQLObjectResultSet has a new is_empty method that behaves the same
  as the existing __nonzero__ method. It should be used in
  preference to __nonzero__ which isn't supported by ResultSet,
  whereas is_empty is.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good.

review: Approve
Revision history for this message
Robert Collins (lifeless) wrote :

Looks good to me too FWIW.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'storm/sqlobject.py'
--- storm/sqlobject.py 2009-04-24 04:05:13 +0000
+++ storm/sqlobject.py 2010-08-02 17:55:59 +0000
@@ -552,6 +552,16 @@
552 return item in result_set552 return item in result_set
553553
554 def __nonzero__(self):554 def __nonzero__(self):
555 """Return C{True} if this result set doesn't contain any results.
556
557 @note: This method is provided for compatibility with SQL Object. For
558 new code, prefer L{is_empty}. It's compatible with L{ResultSet}
559 which doesn't have a C{__nonzero__} implementation.
560 """
561 return self.is_empty()
562
563 def is_empty(self):
564 """Return C{True} if this result set doesn't contain any results."""
555 result_set = self._without_prejoins()._result_set565 result_set = self._without_prejoins()._result_set
556 return not result_set.is_empty()566 return not result_set.is_empty()
557567
558568
=== modified file 'storm/store.py'
--- storm/store.py 2010-07-23 09:44:39 +0000
+++ storm/store.py 2010-08-02 17:55:59 +0000
@@ -1046,7 +1046,7 @@
1046 return result.get_one() is not None1046 return result.get_one() is not None
10471047
1048 def is_empty(self):1048 def is_empty(self):
1049 """Return true if this L{ResultSet} contains no results."""1049 """Return C{True} if this result set doesn't contain any results."""
1050 subselect = self._get_select()1050 subselect = self._get_select()
1051 subselect.limit = 11051 subselect.limit = 1
1052 subselect.order_by = Undef1052 subselect.order_by = Undef
10531053
=== modified file 'tests/sqlobject.py'
--- tests/sqlobject.py 2009-04-24 03:35:36 +0000
+++ tests/sqlobject.py 2010-08-02 17:55:59 +0000
@@ -783,11 +783,27 @@
783 self.assertEquals(list(result.__iter__())[0].name, "John Joe")783 self.assertEquals(list(result.__iter__())[0].name, "John Joe")
784784
785 def test_result_set__nonzero__(self):785 def test_result_set__nonzero__(self):
786 """
787 L{SQLObjectResultSet.__nonzero__} returns C{True} if the result set
788 doesn't contain any results. If it does contain results, C{False} is
789 returned.
790 """
786 result = self.Person.select()791 result = self.Person.select()
787 self.assertEquals(result.__nonzero__(), True)792 self.assertEquals(result.__nonzero__(), True)
788 result = self.Person.select(self.Person.q.name == "No Person")793 result = self.Person.select(self.Person.q.name == "No Person")
789 self.assertEquals(result.__nonzero__(), False)794 self.assertEquals(result.__nonzero__(), False)
790795
796 def test_result_set_is_empty(self):
797 """
798 L{SQLObjectResultSet.is_empty} returns C{True} if the result set
799 doesn't contain any results. If it does contain results, C{False} is
800 returned.
801 """
802 result = self.Person.select()
803 self.assertEquals(result.is_empty(), True)
804 result = self.Person.select(self.Person.q.name == "No Person")
805 self.assertEquals(result.is_empty(), False)
806
791 def test_result_set_distinct(self):807 def test_result_set_distinct(self):
792 result = self.Person.select("person.name = 'John Joe'",808 result = self.Person.select("person.name = 'John Joe'",
793 clauseTables=["phone"])809 clauseTables=["phone"])

Subscribers

People subscribed via source and target branches

to status/vote changes: