divmod-dev team mailing list archive
-
divmod-dev team
-
Mailing list archive
-
Message #00591
[Merge] lp:~divmod-dev/divmod.org/1304710-storeless-adapter into lp:divmod.org
Tristan Seligmann has proposed merging lp:~divmod-dev/divmod.org/1304710-storeless-adapter into lp:divmod.org.
Requested reviews:
Divmod-dev (divmod-dev)
Related bugs:
Bug #1304710 in Divmod: "Adapting a storeless Item via an adapter fails"
https://bugs.launchpad.net/divmod.org/+bug/1304710
For more details, see:
https://code.launchpad.net/~divmod-dev/divmod.org/1304710-storeless-adapter/+merge/214852
--
https://code.launchpad.net/~divmod-dev/divmod.org/1304710-storeless-adapter/+merge/214852
Your team Divmod-dev is requested to review the proposed merge of lp:~divmod-dev/divmod.org/1304710-storeless-adapter into lp:divmod.org.
=== modified file 'Axiom/axiom/item.py'
--- Axiom/axiom/item.py 2014-01-22 14:52:54 +0000
+++ Axiom/axiom/item.py 2014-04-08 23:06:55 +0000
@@ -317,11 +317,7 @@
# adapt every powerup to IPowerupIndirector, calling this method.
return
- try:
- pups = self.powerupsFor(interface)
- except AttributeError: # self.store is None -> self.store.query...
- return
-
+ pups = self.powerupsFor(interface)
aggregator = self.aggregateInterfaces.get(interface, None)
if aggregator is not None:
return aggregator(self, pups)
@@ -342,6 +338,8 @@
inMemoryPowerup = self._inMemoryPowerups.get(interface, None)
if inMemoryPowerup is not None:
yield inMemoryPowerup
+ if self.store is None:
+ return
name = unicode(qual(interface), 'ascii')
for cable in self.store.query(
_PowerupConnector,
=== modified file 'Axiom/axiom/test/test_powerup.py'
--- Axiom/axiom/test/test_powerup.py 2013-02-07 16:39:15 +0000
+++ Axiom/axiom/test/test_powerup.py 2014-04-08 23:06:55 +0000
@@ -1,5 +1,6 @@
from twisted.trial import unittest
+from twisted.python.components import registerAdapter
from axiom.item import Item
from axiom.store import Store
@@ -285,6 +286,16 @@
+class ItemWithAdapter(Item):
+ """
+ An item which will have an adapter registered for its type.
+ """
+ attribute = integer()
+
+registerAdapter(lambda o: 42, ItemWithAdapter, ISumProducer)
+
+
+
class InMemoryPowerupTests(unittest.TestCase):
"""
Tests for the behavior of powerups which are not database-resident.
@@ -323,3 +334,23 @@
"""
powerup, item = self._createEmpowered(withStore=False)
self.assertIdentical(ISumProducer(item), powerup)
+
+
+ def test_noPowerups(self):
+ """
+ L{Item.powerupsFor} returns no powerups for a storeless item with no
+ powerups for the given interface, and adaption to the interface fails
+ with L{TypeError}.
+ """
+ item = SumContributor()
+ self.assertEquals(list(item.powerupsFor(ISumProducer)), [])
+ self.assertRaises(TypeError, ISumProducer, item)
+
+
+ def test_adapterNoPowerups(self):
+ """
+ Adapting an item to an interface for which no powerups are installed
+ will allow adaption to procede via a registered adapter.
+ """
+ item = ItemWithAdapter()
+ self.assertEquals(ISumProducer(item), 42)
Follow ups