def test_respondToChallengeInorrectly(self): """ Test that when an incorrect response is received, the current challenge is not expired and the mouse bites you. """ self.mousehood.startChallenging() self.reactorTime.advance(self.mousehood.challengeInterval) correctResponse = japanese.hiragana[ self.mousehood.getCurrentChallenge()] for ch in japanese.hiragana.values(): if ch != correctResponse: self.mousehood.responseReceived(self.player, ch) break else: self.fail("Buggy test") self.reactorTime.advance(0) self.assertIn(self.mousehood.getCurrentChallenge(), japanese.romajiToHiragana[correctResponse]) self.assertEquals(len(self.playerIntelligence.concepts), 2) c = self.playerIntelligence.concepts[1] self.assertEquals( commandutils.flatten(c.plaintext(self.player)), u"%s bites you!\n" % (self.mouseName,))
def test_mouseCanSqueak(self): events.runEventTransaction(self.store, self.mousehood.squeak) self.assertEquals(len(self.playerIntelligence.concepts), 1) event = self.playerIntelligence.concepts[0] self.assertEquals( commandutils.flatten(event.otherMessage.plaintext(self.player)), u"SQUEAK!")
def test_respondToChallengeInorrectly(self): """ Test that when an incorrect response is received, the current challenge is not expired and the mouse bites you. """ self.mousehood.startChallenging() self.reactorTime.advance(self.mousehood.challengeInterval) correctResponse = japanese.hiragana[ self.mousehood.getCurrentChallenge()] for ch in japanese.hiragana.values(): if ch != correctResponse: self.mousehood.responseReceived(self.player, ch) break else: self.fail("Buggy test") self.reactorTime.advance(0) self.assertIn(self.mousehood.getCurrentChallenge(), japanese.romajiToHiragana[correctResponse]) self.assertEquals(len(self.playerIntelligence.concepts), 2) c = self.playerIntelligence.concepts[1] self.assertEquals(commandutils.flatten(c.plaintext(self.player)), u"%s bites you!\n" % (self.mouseName, ))
def conceptAsText(self, concept, observer): """ Express C{concept} to C{observer} and flatten the result into a L{unicode} string. @return: The text result expressing the concept. """ return flatten(ExpressList(concept.concepts(observer)).plaintext(observer))
def assertChallenge(self, concept): """ Assert that the given concept is a challenge from the mouse named self.mouseName, as observed by self.player. """ said = commandutils.flatten(concept.plaintext(self.player)) self.failUnless(said.startswith(u"A %s says, '" % (self.mouseName,)), repr(said)) self.failUnlessIn(said[-3], japanese.hiragana) self.failUnless(said.endswith("'\n"), repr(said))
def conceptAsText(self, concept, observer): """ Express C{concept} to C{observer} and flatten the result into a L{unicode} string. @return: The text result expressing the concept. """ return flatten( ExpressList(concept.concepts(observer)).plaintext(observer))
def assertDarkRoom(self, visible): """ Assert that the given L{IVisible} provider is a dark room. """ descr = visible.visualizeWithContents([]) expressed = descr.plaintext(self.observer) lines = commandutils.flatten(expressed).splitlines() self.assertEquals( lines, [u"[ Blackness ]", u"You cannot see anything because it is very dark."])
def assertDarkRoom(self, visible): """ Assert that the given L{IVisible} provider is a dark room. """ descr = visible.visualizeWithContents([]) expressed = descr.plaintext(self.observer) lines = commandutils.flatten(expressed).splitlines() self.assertEquals(lines, [ u"[ Blackness ]", u"You cannot see anything because it is very dark." ])
def expandToText(self, template, values): """ Expand the given L{ConceptTemplate} with the given values and flatten the result into a L{unicode} string. @param template: a L{ConceptTemplate} with some markup in it @param values: the values to interpolate into C{template} @return: the text resulting from rendering the given template @rtype: L{unicode} """ return flatten(ExpressList(template.expand(values)).plaintext(None))
def test_mouseCanSqueak(self): """ When explicitly told to challenge with a given romaji syllable, the mouse should say a hiragana letter. """ events.runEventTransaction(self.store, self.mousehood.challenge, character=u"\N{HIRAGANA LETTER A}") self.assertEquals(len(self.playerIntelligence.concepts), 1) event = self.playerIntelligence.concepts[0] self.assertEquals( commandutils.flatten(event.otherMessage.plaintext(self.player)), u"A %s says, '\N{HIRAGANA LETTER A}'" % (self.mouseName, ))
def test_mouseCanSqueak(self): """ When explicitly told to challenge with a given romaji syllable, the mouse should say a hiragana letter. """ events.runEventTransaction( self.store, self.mousehood.challenge, character=u"\N{HIRAGANA LETTER A}") self.assertEquals(len(self.playerIntelligence.concepts), 1) event = self.playerIntelligence.concepts[0] self.assertEquals( commandutils.flatten(event.otherMessage.plaintext(self.player)), u"A %s says, '\N{HIRAGANA LETTER A}'" % (self.mouseName,))
def testLookAtExitNameEventBroadcasting(self): target = objects.Thing( store=self.store, name=u"Visible Location", description=u"Description of visible location.", proper=True) objects.Container.createFor(target, capacity=1000) objects.Exit.link(self.location, target, u"south") action.LookAt().runEventTransaction( self.player, u"look", {"target": u"south"}) evts = self.actor.getIntelligence().observedConcepts self.assertEquals(len(evts), 1) self.failUnless(isinstance(evts[0], events.Success)) self.assertEquals( commandutils.flatten(evts[0].actorMessage.plaintext(self.actor)), u"[ Visible Location ]\n( north )\nDescription of visible location.\n")
def test_mouseSqueaksAtIntruders(self): """ When a mean old man walks into the mouse's clock, the mouse will squeak ruthlessly. """ clock = task.Clock() self.mousehood._callLater = clock.callLater evt = events.ArrivalEvent(actor=self.player) self.mouseActor.send(evt) self.assertEquals(len(self.playerIntelligence.concepts), 0) clock.advance(0) self.assertEquals(len(self.playerIntelligence.concepts), 1) event = self.playerIntelligence.concepts[0] self.assertEquals( commandutils.flatten(event.otherMessage.plaintext(self.player)), u"SQUEAK!")
def test_exitNameEventBroadcasting(self): target = objects.Thing(store=self.context.store, name=u"Visible Location", description=u"Description of visible location.", proper=True) objects.Container.createFor(target, capacity=1000) objects.Exit.link(self.context.location, target, u"south") action.LookAt().runEventTransaction(self.context.player, u"look", {"target": u"south"}) evts = self.context.actor.getIntelligence().observedConcepts self.assertEqual(1, len(evts)) self.assertIsInstance(evts[0], events.Success) self.assertEqual( dedent(u""" [ Visible Location ] ( north ) Description of visible location. """).lstrip(), flatten(evts[0].actorMessage.plaintext(self.context.actor.thing)))
def test_playerSaysCorrectThing(self): """ Test that when someone gives voice to the correct response to a mouse's current challenge, the mouse acknowledges this with a salute. """ self.mousehood.startChallenging() self.reactorTime.advance(self.mousehood.challengeInterval) action.Say().do( # http://divmod.org/trac/ticket/2917 iimaginary.IActor(self.player), None, japanese.hiragana[self.mousehood.getCurrentChallenge()]) self.assertIdentical(self.mousehood.getCurrentChallenge(), None) self.reactorTime.advance(0) self.assertEquals(len(self.playerIntelligence.concepts), 3) c = self.playerIntelligence.concepts[2] self.assertEquals(commandutils.flatten(c.plaintext(self.player)), u"%s salutes you!\n" % (self.mouseName, ))
def test_respondToChallengeCorrectly(self): """ Test that when a correct response is received, the current challenge is expired and the mouse salutes you. """ self.mousehood.startChallenging() self.reactorTime.advance(self.mousehood.challengeInterval) correctResponse = japanese.hiragana[ self.mousehood.getCurrentChallenge()] self.mousehood.responseReceived(self.player, correctResponse) self.reactorTime.advance(0) self.assertIdentical(self.mousehood.getCurrentChallenge(), None) self.assertEquals(len(self.playerIntelligence.concepts), 2) c = self.playerIntelligence.concepts[1] self.assertEquals(commandutils.flatten(c.plaintext(self.player)), u"%s salutes you!\n" % (self.mouseName, ))
def test_playerSaysIncorrectThing(self): """ Test that when someone gives voice to the correct response to a mouse's current challenge, the mouse acknowledges this with a salute. """ self.mousehood.startChallenging() self.reactorTime.advance(self.mousehood.challengeInterval) action.Say().do( # http://divmod.org/trac/ticket/2917 iimaginary.IActor(self.player), None, u"lolololo pew") self.failIfIdentical(self.mousehood.getCurrentChallenge(), None) self.reactorTime.advance(0) self.assertEquals(len(self.playerIntelligence.concepts), 3) c = self.playerIntelligence.concepts[2] self.assertEquals( commandutils.flatten(c.plaintext(self.player)), u"%s bites you!\n" % (self.mouseName,))
def test_exitNameEventBroadcasting(self): target = objects.Thing( store=self.context.store, name=u"Visible Location", description=u"Description of visible location.", proper=True) objects.Container.createFor(target, capacity=1000) objects.Exit.link(self.context.location, target, u"south") action.LookAt().runEventTransaction( self.context.player, u"look", {"target": u"south"}) evts = self.context.actor.getIntelligence().observedConcepts self.assertEqual(1, len(evts)) self.assertIsInstance(evts[0], events.Success) self.assertEqual( dedent(u""" [ Visible Location ] ( north ) Description of visible location. """).lstrip(), flatten(evts[0].actorMessage.plaintext(self.context.actor.thing)))
def test_respondToChallengeCorrectly(self): """ Test that when a correct response is received, the current challenge is expired and the mouse salutes you. """ self.mousehood.startChallenging() self.reactorTime.advance(self.mousehood.challengeInterval) correctResponse = japanese.hiragana[ self.mousehood.getCurrentChallenge()] self.mousehood.responseReceived(self.player, correctResponse) self.reactorTime.advance(0) self.assertIdentical(self.mousehood.getCurrentChallenge(), None) self.assertEquals(len(self.playerIntelligence.concepts), 2) c = self.playerIntelligence.concepts[1] self.assertEquals( commandutils.flatten(c.plaintext(self.player)), u"%s salutes you!\n" % (self.mouseName,))
def function(thing): return flatten(getattr(Noun(thing), nounFormMethod)().plaintext(None))
def expandToText(self, template, values): """ Expand the given L{ConceptTemplate} with the given values and flatten the result into a L{unicode} string. """ return flatten(ExpressList(template.expand(values)).plaintext(None))