Merge lp:~divmod-dev/divmod.org/1304710-storeless-adapter into lp:divmod.org

Proposed by Tristan Seligmann on 2014-04-08
Status: Merged
Merged at revision: 2748
Proposed branch: lp:~divmod-dev/divmod.org/1304710-storeless-adapter
Merge into: lp:divmod.org
Diff against target: 77 lines (+34/-5)
2 files modified
Axiom/axiom/item.py (+3/-5)
Axiom/axiom/test/test_powerup.py (+31/-0)
To merge this branch: bzr merge lp:~divmod-dev/divmod.org/1304710-storeless-adapter
Reviewer Review Type Date Requested Status
Tristan Seligmann Needs Fixing on 2014-04-16
Jonathan Jacobs 2014-04-08 Approve on 2014-04-09
Review via email: mp+214852@code.launchpad.net
To post a comment you must log in.
Jonathan Jacobs (jjacobs) wrote :

This looks good to me, although it would be useful to get a second opinion, in particular from the original author.

review: Approve
Tristan Seligmann (mithrandi) wrote :

Note to self: fix "procede" typo.

review: Needs Fixing
Laurens Van Houtven (lvh) wrote :

Looks good modulo your typo :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Axiom/axiom/item.py'
2--- Axiom/axiom/item.py 2014-01-22 14:52:54 +0000
3+++ Axiom/axiom/item.py 2014-04-08 23:06:55 +0000
4@@ -317,11 +317,7 @@
5 # adapt every powerup to IPowerupIndirector, calling this method.
6 return
7
8- try:
9- pups = self.powerupsFor(interface)
10- except AttributeError: # self.store is None -> self.store.query...
11- return
12-
13+ pups = self.powerupsFor(interface)
14 aggregator = self.aggregateInterfaces.get(interface, None)
15 if aggregator is not None:
16 return aggregator(self, pups)
17@@ -342,6 +338,8 @@
18 inMemoryPowerup = self._inMemoryPowerups.get(interface, None)
19 if inMemoryPowerup is not None:
20 yield inMemoryPowerup
21+ if self.store is None:
22+ return
23 name = unicode(qual(interface), 'ascii')
24 for cable in self.store.query(
25 _PowerupConnector,
26
27=== modified file 'Axiom/axiom/test/test_powerup.py'
28--- Axiom/axiom/test/test_powerup.py 2013-02-07 16:39:15 +0000
29+++ Axiom/axiom/test/test_powerup.py 2014-04-08 23:06:55 +0000
30@@ -1,5 +1,6 @@
31
32 from twisted.trial import unittest
33+from twisted.python.components import registerAdapter
34
35 from axiom.item import Item
36 from axiom.store import Store
37@@ -285,6 +286,16 @@
38
39
40
41+class ItemWithAdapter(Item):
42+ """
43+ An item which will have an adapter registered for its type.
44+ """
45+ attribute = integer()
46+
47+registerAdapter(lambda o: 42, ItemWithAdapter, ISumProducer)
48+
49+
50+
51 class InMemoryPowerupTests(unittest.TestCase):
52 """
53 Tests for the behavior of powerups which are not database-resident.
54@@ -323,3 +334,23 @@
55 """
56 powerup, item = self._createEmpowered(withStore=False)
57 self.assertIdentical(ISumProducer(item), powerup)
58+
59+
60+ def test_noPowerups(self):
61+ """
62+ L{Item.powerupsFor} returns no powerups for a storeless item with no
63+ powerups for the given interface, and adaption to the interface fails
64+ with L{TypeError}.
65+ """
66+ item = SumContributor()
67+ self.assertEquals(list(item.powerupsFor(ISumProducer)), [])
68+ self.assertRaises(TypeError, ISumProducer, item)
69+
70+
71+ def test_adapterNoPowerups(self):
72+ """
73+ Adapting an item to an interface for which no powerups are installed
74+ will allow adaption to procede via a registered adapter.
75+ """
76+ item = ItemWithAdapter()
77+ self.assertEquals(ISumProducer(item), 42)

Subscribers

People subscribed via source and target branches

to all changes: