From 68e29b49268438bfb2a8faecf815878f0a0f9896 Mon Sep 17 00:00:00 2001 From: David Sturgis Date: Sun, 8 Mar 2015 18:04:53 -0400 Subject: [PATCH 1/2] Add (broken) test for desc component ordering Basic description component ordering test for two intentionally mis-ordered components; Shouldn't actually pass(?!) but does... --- imaginary/test/test_concept.py | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/imaginary/test/test_concept.py b/imaginary/test/test_concept.py index d9e712a..8f113ab 100644 --- a/imaginary/test/test_concept.py +++ b/imaginary/test/test_concept.py @@ -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): @@ -221,6 +224,47 @@ def test_components(self): b.original ) +@implementer(iimaginary.IDescriptionContributor) +class beforeDescription(item.Item): + desc = u"before" + comesBefore = [] + comesAfter = [] + 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 = [] + comesAfter = [beforeDescription] + 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_twoItemOrdering(self): + viewedThing = objects.Thing( + store=self.store, + location=self.player.location, + name=u"viewed") + + # Apply with wrong priorities! + viewedThing.powerUp( + beforeDescription(store=self.store), + priority=item.POWERUP_AFTER) + viewedThing.powerUp( + afterDescription(store=self.store), + priority=item.POWERUP_BEFORE) + + self.assertCommandOutput( + "look at viewed", + [commandutils.E(u"[ viewed ]"), + beforeDescription.desc, + afterDescription.desc]) @implementer(iimaginary.IExit) class StubExit(structlike.record("name")): From b2ee1f2d8354bee34220e9918f332cd75ba48910 Mon Sep 17 00:00:00 2001 From: David Sturgis Date: Sun, 8 Mar 2015 18:15:55 -0400 Subject: [PATCH 2/2] Improve test_twoComponentOrdering implementation Now fails in a much more intentional / revealing way. --- imaginary/test/test_concept.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/imaginary/test/test_concept.py b/imaginary/test/test_concept.py index 8f113ab..211e0fc 100644 --- a/imaginary/test/test_concept.py +++ b/imaginary/test/test_concept.py @@ -227,8 +227,8 @@ def test_components(self): @implementer(iimaginary.IDescriptionContributor) class beforeDescription(item.Item): desc = u"before" - comesBefore = [] - comesAfter = [] + comesBefore = attributes.inmemory() + comesAfter = attributes.inmemory() myattr = attributes.integer(default=0) powerupInterfaces = [iimaginary.IDescriptionContributor] def contributeDescriptionFrom(self, paths): @@ -237,8 +237,8 @@ def contributeDescriptionFrom(self, paths): @implementer(iimaginary.IDescriptionContributor) class afterDescription(item.Item): desc = u"after" - comesBefore = [] - comesAfter = [beforeDescription] + comesBefore = attributes.inmemory() + comesAfter = attributes.inmemory() myattr = attributes.integer(default=0) powerupInterfaces = [iimaginary.IDescriptionContributor] def contributeDescriptionFrom(self, paths): @@ -246,25 +246,40 @@ def contributeDescriptionFrom(self, paths): class VisualizationTest(commandutils.CommandTestCaseMixin, unittest.TestCase): - def test_twoItemOrdering(self): + 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( - beforeDescription(store=self.store), + bd, priority=item.POWERUP_AFTER) viewedThing.powerUp( - afterDescription(store=self.store), + ad, priority=item.POWERUP_BEFORE) self.assertCommandOutput( "look at viewed", [commandutils.E(u"[ viewed ]"), - beforeDescription.desc, - afterDescription.desc]) + 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")):