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
1=== modified file 'NEWS'
2--- NEWS 2020-03-18 16:31:08 +0000
3+++ NEWS 2020-03-18 16:51:15 +0000
4@@ -14,6 +14,7 @@
5 not generally needed.
6 - A new block_access context manager blocks database access for one
7 or more stores in the managed scope.
8+- Implement is_empty on bound ReferenceSets.
9
10 Bug fixes
11 ---------
12
13=== modified file 'storm/references.py'
14--- storm/references.py 2020-03-13 17:06:37 +0000
15+++ storm/references.py 2020-03-18 16:51:15 +0000
16@@ -299,6 +299,9 @@
17 def __contains__(self, item):
18 return item in self.find()
19
20+ def is_empty(self):
21+ return self.find().is_empty()
22+
23 def first(self, *args, **kwargs):
24 return self.find(*args, **kwargs).first()
25
26
27=== modified file 'storm/tests/store/base.py'
28--- storm/tests/store/base.py 2020-03-18 16:31:08 +0000
29+++ storm/tests/store/base.py 2020-03-18 16:51:15 +0000
30@@ -3845,6 +3845,13 @@
31 (400, 20, "Title 100"),
32 ])
33
34+ def test_reference_set_is_empty(self):
35+ foo = self.store.get(FooRefSet, 20)
36+ self.assertFalse(foo.bars.is_empty())
37+
38+ foo.bars.clear()
39+ self.assertTrue(foo.bars.is_empty())
40+
41 def test_reference_set_count(self):
42 self.add_reference_set_bar_400()
43
44@@ -4210,6 +4217,13 @@
45 items = [(bar.id, bar.foo_id, bar.title) for bar in foo.bars]
46 self.assertEqual(items, [])
47
48+ def test_indirect_reference_set_is_empty(self):
49+ foo = self.store.get(FooIndRefSet, 20)
50+ self.assertFalse(foo.bars.is_empty())
51+
52+ foo.bars.clear()
53+ self.assertTrue(foo.bars.is_empty())
54+
55 def test_indirect_reference_set_count(self):
56 foo = self.store.get(FooIndRefSet, 20)
57 self.assertEqual(foo.bars.count(), 2)

Subscribers

People subscribed via source and target branches

to status/vote changes: