Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Description component ordering #67

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions imaginary/test/test_concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

from epsilon import structlike

from axiom import item, attributes

from imaginary import language, unc, text as T, iimaginary
from imaginary.test import commandutils
from imaginary import objects

class FakeThing(object):
def __init__(self, **kw):
Expand Down Expand Up @@ -221,6 +224,62 @@ def test_components(self):
b.original
)

@implementer(iimaginary.IDescriptionContributor)
class beforeDescription(item.Item):
desc = u"before"
comesBefore = attributes.inmemory()
comesAfter = attributes.inmemory()
myattr = attributes.integer(default=0)
powerupInterfaces = [iimaginary.IDescriptionContributor]
def contributeDescriptionFrom(self, paths):
return language.ExpressString(self.desc)

@implementer(iimaginary.IDescriptionContributor)
class afterDescription(item.Item):
desc = u"after"
comesBefore = attributes.inmemory()
comesAfter = attributes.inmemory()
myattr = attributes.integer(default=0)
powerupInterfaces = [iimaginary.IDescriptionContributor]
def contributeDescriptionFrom(self, paths):
return language.ExpressString(self.desc)

class VisualizationTest(commandutils.CommandTestCaseMixin, unittest.TestCase):

def test_twoComponentOrdering(self):
viewedThing = objects.Thing(
store=self.store,
location=self.player.location,
name=u"viewed")

bd = beforeDescription(store=self.store)
ad = afterDescription(store=self.store)

bd.comesAfter = []
ad.comesAfter = [beforeDescription]

# Apply with wrong priorities!
viewedThing.powerUp(
bd,
priority=item.POWERUP_AFTER)
viewedThing.powerUp(
ad,
priority=item.POWERUP_BEFORE)

self.assertCommandOutput(
"look at viewed",
[commandutils.E(u"[ viewed ]"),
bd.desc,
ad.desc])

ad.comesAfter = []
bd.comesAfter = [afterDescription]

self.assertCommandOutput(
"look at viewed",
[commandutils.E(u"[ viewed ]"),
ad.desc,
bd.desc])

@implementer(iimaginary.IExit)
class StubExit(structlike.record("name")):
Expand Down