Example #1
0
    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,))
Example #2
0
 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!")
Example #3
0
    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, ))
Example #4
0
 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!")
Example #5
0
    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))
Example #6
0
 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))
Example #7
0
 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))
Example #8
0
    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))
Example #9
0
    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."])
Example #10
0
    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."
        ])
Example #11
0
    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))
Example #12
0
    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))
Example #13
0
    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, ))
Example #14
0
    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,))
Example #15
0
    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")
Example #16
0
    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!")
Example #17
0
    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!")
Example #18
0
    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)))
Example #19
0
    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, ))
Example #20
0
    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, ))
Example #21
0
    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,))
Example #22
0
    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)))
Example #23
0
    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,))
Example #24
0
 def function(thing):
     return flatten(getattr(Noun(thing), nounFormMethod)().plaintext(None))
Example #25
0
 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))
Example #26
0
 def function(thing):
     return flatten(getattr(Noun(thing), nounFormMethod)().plaintext(None))