Merge lp:~cjwatson/storm/reference-set-is-empty into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 548
Proposed branch: lp:~cjwatson/storm/reference-set-is-empty
Merge into: lp:storm
Diff against target: 57 lines (+18/-0)
3 files modified
NEWS (+1/-0)
storm/references.py (+3/-0)
storm/tests/store/base.py (+14/-0)
To merge this branch: bzr merge lp:~cjwatson/storm/reference-set-is-empty
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Storm Developers Pending
Review via email: mp+380837@code.launchpad.net

Commit message

Implement is_empty on bound ReferenceSets.

Description of the change

This works on ordinary ResultSets, and can easily work on bound ReferenceSets too.

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2020-03-18 16:31:08 +0000
+++ NEWS 2020-03-18 16:51:15 +0000
@@ -14,6 +14,7 @@
14 not generally needed.14 not generally needed.
15- A new block_access context manager blocks database access for one15- A new block_access context manager blocks database access for one
16 or more stores in the managed scope.16 or more stores in the managed scope.
17- Implement is_empty on bound ReferenceSets.
1718
18Bug fixes19Bug fixes
19---------20---------
2021
=== modified file 'storm/references.py'
--- storm/references.py 2020-03-13 17:06:37 +0000
+++ storm/references.py 2020-03-18 16:51:15 +0000
@@ -299,6 +299,9 @@
299 def __contains__(self, item):299 def __contains__(self, item):
300 return item in self.find()300 return item in self.find()
301301
302 def is_empty(self):
303 return self.find().is_empty()
304
302 def first(self, *args, **kwargs):305 def first(self, *args, **kwargs):
303 return self.find(*args, **kwargs).first()306 return self.find(*args, **kwargs).first()
304307
305308
=== modified file 'storm/tests/store/base.py'
--- storm/tests/store/base.py 2020-03-18 16:31:08 +0000
+++ storm/tests/store/base.py 2020-03-18 16:51:15 +0000
@@ -3845,6 +3845,13 @@
3845 (400, 20, "Title 100"),3845 (400, 20, "Title 100"),
3846 ])3846 ])
38473847
3848 def test_reference_set_is_empty(self):
3849 foo = self.store.get(FooRefSet, 20)
3850 self.assertFalse(foo.bars.is_empty())
3851
3852 foo.bars.clear()
3853 self.assertTrue(foo.bars.is_empty())
3854
3848 def test_reference_set_count(self):3855 def test_reference_set_count(self):
3849 self.add_reference_set_bar_400()3856 self.add_reference_set_bar_400()
38503857
@@ -4210,6 +4217,13 @@
4210 items = [(bar.id, bar.foo_id, bar.title) for bar in foo.bars]4217 items = [(bar.id, bar.foo_id, bar.title) for bar in foo.bars]
4211 self.assertEqual(items, [])4218 self.assertEqual(items, [])
42124219
4220 def test_indirect_reference_set_is_empty(self):
4221 foo = self.store.get(FooIndRefSet, 20)
4222 self.assertFalse(foo.bars.is_empty())
4223
4224 foo.bars.clear()
4225 self.assertTrue(foo.bars.is_empty())
4226
4213 def test_indirect_reference_set_count(self):4227 def test_indirect_reference_set_count(self):
4214 foo = self.store.get(FooIndRefSet, 20)4228 foo = self.store.get(FooIndRefSet, 20)
4215 self.assertEqual(foo.bars.count(), 2)4229 self.assertEqual(foo.bars.count(), 2)

Subscribers

People subscribed via source and target branches

to status/vote changes: