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
1=== modified file 'storm/sqlobject.py'
2--- storm/sqlobject.py 2009-04-24 04:05:13 +0000
3+++ storm/sqlobject.py 2010-08-02 17:55:59 +0000
4@@ -552,6 +552,16 @@
5 return item in result_set
6
7 def __nonzero__(self):
8+ """Return C{True} if this result set doesn't contain any results.
9+
10+ @note: This method is provided for compatibility with SQL Object. For
11+ new code, prefer L{is_empty}. It's compatible with L{ResultSet}
12+ which doesn't have a C{__nonzero__} implementation.
13+ """
14+ return self.is_empty()
15+
16+ def is_empty(self):
17+ """Return C{True} if this result set doesn't contain any results."""
18 result_set = self._without_prejoins()._result_set
19 return not result_set.is_empty()
20
21
22=== modified file 'storm/store.py'
23--- storm/store.py 2010-07-23 09:44:39 +0000
24+++ storm/store.py 2010-08-02 17:55:59 +0000
25@@ -1046,7 +1046,7 @@
26 return result.get_one() is not None
27
28 def is_empty(self):
29- """Return true if this L{ResultSet} contains no results."""
30+ """Return C{True} if this result set doesn't contain any results."""
31 subselect = self._get_select()
32 subselect.limit = 1
33 subselect.order_by = Undef
34
35=== modified file 'tests/sqlobject.py'
36--- tests/sqlobject.py 2009-04-24 03:35:36 +0000
37+++ tests/sqlobject.py 2010-08-02 17:55:59 +0000
38@@ -783,11 +783,27 @@
39 self.assertEquals(list(result.__iter__())[0].name, "John Joe")
40
41 def test_result_set__nonzero__(self):
42+ """
43+ L{SQLObjectResultSet.__nonzero__} returns C{True} if the result set
44+ doesn't contain any results. If it does contain results, C{False} is
45+ returned.
46+ """
47 result = self.Person.select()
48 self.assertEquals(result.__nonzero__(), True)
49 result = self.Person.select(self.Person.q.name == "No Person")
50 self.assertEquals(result.__nonzero__(), False)
51
52+ def test_result_set_is_empty(self):
53+ """
54+ L{SQLObjectResultSet.is_empty} returns C{True} if the result set
55+ doesn't contain any results. If it does contain results, C{False} is
56+ returned.
57+ """
58+ result = self.Person.select()
59+ self.assertEquals(result.is_empty(), True)
60+ result = self.Person.select(self.Person.q.name == "No Person")
61+ self.assertEquals(result.is_empty(), False)
62+
63 def test_result_set_distinct(self):
64 result = self.Person.select("person.name = 'John Joe'",
65 clauseTables=["phone"])

Subscribers

People subscribed via source and target branches

to status/vote changes: