예제 #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,))
예제 #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!")
예제 #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, ))
예제 #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!")
예제 #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))
예제 #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))
예제 #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))
예제 #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))
예제 #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."])
예제 #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."
        ])
예제 #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))
예제 #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))
예제 #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, ))
예제 #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,))
예제 #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")
예제 #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!")
예제 #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!")
예제 #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)))
예제 #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, ))
예제 #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, ))
예제 #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,))
예제 #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)))
예제 #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,))
예제 #24
0
 def function(thing):
     return flatten(getattr(Noun(thing), nounFormMethod)().plaintext(None))
예제 #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))
예제 #26
0
 def function(thing):
     return flatten(getattr(Noun(thing), nounFormMethod)().plaintext(None))