コード例 #1
0
    def testRestore(self):
        self._test(
            "restore foobar",
            [E("Who's that?")])

        self._test(
            "restore here",
            ["Test Location cannot be restored."])

        actor = iimaginary.IActor(self.player)
        actor.hitpoints.decrease(25)
        actor.stamina.decrease(25)
        self._test(
            "restore self",
            ["You have fully restored yourself."])
        self.assertEquals(actor.hitpoints.current,
                          actor.hitpoints.max)
        self.assertEquals(actor.stamina.current,
                          actor.stamina.max)

        oactor = iimaginary.IActor(self.observer)
        oactor.hitpoints.decrease(25)
        oactor.stamina.decrease(25)
        self._test(
            "restore Observer Player",
            ["You have restored Observer Player to full health."],
            ["Test Player has restored you to full health."])
        self.assertEquals(oactor.hitpoints.current,
                          oactor.hitpoints.max)
        self.assertEquals(oactor.stamina.current,
                          oactor.stamina.max)
コード例 #2
0
    def testScore(self):
        # XXX This is kind of weak.  How can this test be improved?
        x, y = self._test("score", [
            ".*", ".*Level: +(\\d+) Experience: +(\\d+)",
            ".*Hitpoints: +(\\d+)/(\\d+)", ".*Stamina: +(\\d+)/(\\d+)", ".*"
        ])
        self.assertEquals(x[0].groups(), ())  # Extra line for the command
        self.assertEquals(x[1].groups(), ())
        self.assertEquals(x[2].groups(), ('0', '0'))
        self.assertEquals(x[3].groups(), ('100', '100'))
        self.assertEquals(x[4].groups(), ('100', '100'))
        self.assertEquals(x[5].groups(), ())

        actor = iimaginary.IActor(self.player)
        actor.level = 3
        actor.experience = 63
        actor.hitpoints.current = 32
        actor.hitpoints.max = 74
        actor.stamina.current = 12
        actor.stamina.max = 39
        x, y = self._test("score", [
            ".*", ".*Level: +(\\d+) Experience: +(\\d+)",
            ".*Hitpoints: +(\\d+)/(\\d+)", ".*Stamina: +(\\d+)/(\\d+)", ".*"
        ])
        self.assertEquals(x[0].groups(), ())
        self.assertEquals(x[1].groups(), ())
        self.assertEquals(x[2].groups(), ('3', '63'))
        self.assertEquals(x[3].groups(), ('32', '74'))
        self.assertEquals(x[4].groups(), ('12', '39'))
        self.assertEquals(x[5].groups(), ())
コード例 #3
0
    def test_creation(self):
        """
        Test the creation of a hiragana-speaking mouse using the thing creation
        plugin system.
        """
        self._test(
            u"create the 'hiragana mouse' named " + self.mouseName,
            [commandutils.E(u"You create " + self.mouseName + u".")],
            [commandutils.E(u"Test Player creates %s." % (self.mouseName,))])

        for thing in self.location.findProviders(iimaginary.IThing, 0):
            if thing.name == self.mouseName:
                break
        else:
            self.fail("Could not find the mouse!  Test bug.")

        clock = task.Clock()
        jimhood = iimaginary.IActor(thing).getIntelligence()
        jimhood._callLater = clock.callLater

        self._test(
            u"drop " + self.mouseName,
            [commandutils.E(u"You drop %s." % (self.mouseName,))],
            [commandutils.E(u"Test Player drops %s." % (self.mouseName,))])

        clock.advance(jimhood.challengeInterval)

        self._test(
            None,
            [self.speechPattern],
            [self.speechPattern])
コード例 #4
0
    def test_oneManEnters(self):
        """
        Test that when a fellow jaunts into a venue inhabited by a mouse of the
        Nipponese persuasion, a hiragana allocution follows.
        """
        clock = task.Clock()

        closetContainer = commandutils.createLocation(self.store, u"Closet",
                                                      None)
        closet = closetContainer.thing

        mouse = mice.createHiraganaMouse(store=self.store,
                                         name=self.mouseName,
                                         proper=True)
        mouseActor = iimaginary.IActor(mouse)
        mousehood = mouseActor.getIntelligence()
        mousehood._callLater = clock.callLater
        mouse.moveTo(closet)

        objects.Exit.link(self.location, closet, u"north")

        self._test("north", [
            commandutils.E("[ Closet ]"),
            commandutils.E("( south )"),
            commandutils.E(u"Here, you see " + self.mouseName + u".")
        ], ["Test Player leaves north."])

        clock.advance(mousehood.challengeInterval)

        self._test(None, [self.speechPattern])
コード例 #5
0
    def testSqueak(self):
        """
        Test that when someone walks into a room with a mouse, the mouse
        squeaks and the person who walked in hears it.
        """
        mouse = mice.createMouse(store=self.store, name=u"squeaker")
        clock = task.Clock()
        intelligence = iimaginary.IActor(mouse).getIntelligence()
        intelligence._callLater = clock.callLater

        elsewhere = commandutils.createLocation(
            self.store, u"Mouse Hole", None).thing

        objects.Exit.link(self.location, elsewhere, u"south")

        mouse.moveTo(elsewhere)

        self._test(
            "south",
            [commandutils.E("[ Mouse Hole ]"),
             commandutils.E("( north )"),
             commandutils.E("Here, you see a squeaker.")],
            ['Test Player leaves south.'])

        clock.advance(0)
        self._test(None, ["SQUEAK!"])
コード例 #6
0
ファイル: test_hit.py プロジェクト: zeeneddie/imaginary
    def testHit(self):
        self._test("hit self", [E("Hit yourself?  Stupid.")])

        self._test("hit foobar", [E("Who's that?")])

        actor = iimaginary.IActor(self.player)
        actor.stamina.current = 0
        self._test("hit Observer Player", ["You're too tired!"])

        actor.stamina.current = actor.stamina.max

        x, y = self._test("hit Observer Player",
                          ["You hit Observer Player for (\\d+) hitpoints."],
                          ["Test Player hits you for (\\d+) hitpoints."])
        self.assertEquals(x[1].groups(), y[0].groups())

        actor.stamina.current = actor.stamina.max

        x, y = self._test("attack Observer Player",
                          ["You hit Observer Player for (\\d+) hitpoints."],
                          ["Test Player hits you for (\\d+) hitpoints."])
        self.assertEquals(x[1].groups(), y[0].groups())

        monster = objects.Thing(store=self.store, name=u"monster")
        objects.Actor.createFor(monster)
        monster.moveTo(self.location)
        x, y = self._test("hit monster",
                          ["You hit the monster for (\\d+) hitpoints."],
                          ["Test Player hits a monster."])
        monster.destroy()
コード例 #7
0
    def testCreation(self):
        """
        Test that a mouse can be created with the create command.
        """
        self._test("create the mouse named squeaker", ['You create squeaker.'],
                   ['Test Player creates squeaker.'])

        [mouse] = list(self.playerContainer.getContents())
        self.failUnless(
            isinstance(iimaginary.IActor(mouse).getIntelligence(), mice.Mouse))
コード例 #8
0
ファイル: test_look.py プロジェクト: zeeneddie/imaginary
    def __init__(self):
        self.store = store.Store()

        locContainer = createLocation(self.store,
                                      name=u"Test Location",
                                      description=u"Location for testing.")
        self.location = locContainer.thing

        self.world = ImaginaryWorld(store=self.store)
        self.player = self.world.create(u"Test Player",
                                        gender=language.Gender.FEMALE)
        locContainer.add(self.player)
        self.actor = iimaginary.IActor(self.player)
        self.actor.setEphemeralIntelligence(TestIntelligence())
コード例 #9
0
ファイル: test_who.py プロジェクト: zeeneddie/imaginary
 def setUp(self):
     """
     Create a store and an Imaginary world and populate it with a number
     of players, one of which is equipped to record the events it
     receives.
     """
     self.store = store.Store()
     self.world = ImaginaryWorld(store=self.store)
     self.others = []
     for i in xrange(5):
         self.others.append(self.world.create(u"player-%d" % (i, )))
     self.player = self.world.create(u"testplayer")
     self.actor = iimaginary.IActor(self.player)
     self.intelligence = commandutils.MockEphemeralIntelligence()
     self.actor.setEphemeralIntelligence(self.intelligence)
     self.world.loggedIn(self.player)
コード例 #10
0
    def setUp(self):
        self.store = store.Store()

        self.location = objects.Thing(
            store=self.store,
            name=u"Test Location",
            description=u"Location for testing.",
            proper=True)

        locContainer = objects.Container.createFor(
            self.location, capacity=1000)

        self.world = ImaginaryWorld(store=self.store)
        self.player = self.world.create(u"Test Player", gender=language.Gender.FEMALE)
        locContainer.add(self.player)
        self.actor = iimaginary.IActor(self.player)
        self.actor.setEphemeralIntelligence(TestIntelligence())
コード例 #11
0
    def setUp(self):
        self.store = store.Store()

        self.clock = objects.Thing(store=self.store, name=u"Clock")
        self.clockContainer = objects.Container.createFor(self.clock, capacity=10)

        self.mouse = mice.createMouse(store=self.store, name=u"Squeaker McSqueakenson")
        self.mouseActor = iimaginary.IActor(self.mouse)
        self.mousehood = self.mouseActor.getIntelligence()
        self.mouse.moveTo(self.clock)

        self.player = objects.Thing(store=self.store, name=u"Mean Old Man")
        self.playerActor = objects.Actor.createFor(self.player)
        self.playerIntelligence = commandutils.MockIntelligence(
            store=self.store)
        self.playerActor.setEnduringIntelligence(self.playerIntelligence)

        self.player.moveTo(self.clock)
コード例 #12
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, ))
コード例 #13
0
    def do(self, player, line, direction):
        location = player.location

        evt = events.Success(
            location=location,
            actor=player,
            otherMessage=(player, " leaves ", direction.name, "."))
        evt.broadcast()

        try:
            direction.traverse(player)
        except eimaginary.DoesntFit:
            raise eimaginary.ActionFailure(events.ThatDoesntWork(
                actor=player,
                actorMessage=language.ExpressString(
                        u"There's no room for you there.")))

        # This is subtly incorrect: see http://divmod.org/trac/ticket/2917
        lookAroundActor = iimaginary.IActor(player)
        LookAround().do(lookAroundActor, "look")
コード例 #14
0
    def setUp(self):
        self.store = store.Store()

        self.clock = objects.Thing(store=self.store, name=u"Clock")
        self.clockContainer = objects.Container.createFor(self.clock,
                                                          capacity=10)

        self.mouseName = u"\N{KATAKANA LETTER PI}\N{KATAKANA LETTER SMALL YU}"
        self.mouse = mice.createHiraganaMouse(store=self.store,
                                              name=self.mouseName)
        self.mouseActor = iimaginary.IActor(self.mouse)
        self.mousehood = self.mouseActor.getIntelligence()
        self.mouse.moveTo(self.clock)

        (self.player, self.playerActor,
         self.playerIntelligence) = commandutils.createPlayer(
             self.store, u"Mean Old Man")

        self.player.moveTo(self.clock)

        self.reactorTime = task.Clock()
        self.mousehood._callLater = self.reactorTime.callLater
コード例 #15
0
    def test_creation(self):
        """
        Test the creation of a hiragana-speaking mouse using the thing creation
        plugin system.
        """
        self._test(
            u"create the 'hiragana mouse' named " + self.mouseName,
            [commandutils.E(u"You create " + self.mouseName + u".")],
            [commandutils.E(u"Test Player creates %s." % (self.mouseName, ))])

        [thing] = find(self.location.idea, distance=0, name=self.mouseName)

        clock = task.Clock()
        jimhood = iimaginary.IActor(thing).getIntelligence()
        jimhood._callLater = clock.callLater

        self._test(
            u"drop " + self.mouseName,
            [commandutils.E(u"You drop %s." % (self.mouseName, ))],
            [commandutils.E(u"Test Player drops %s." % (self.mouseName, ))])

        clock.advance(jimhood.challengeInterval)

        self._test(None, [self.speechPattern], [self.speechPattern])
コード例 #16
0
 def __init__(self, actor):
     self.actor = actor
     self.player = iimaginary.IActor(actor)
     self.player.setEphemeralIntelligence(self)
コード例 #17
0
ファイル: test_actor.py プロジェクト: zeeneddie/imaginary
 def testPoweringUp(self):
     o = objects.Thing(store=self.store, name=u"wannabe")
     self.assertEquals(iimaginary.IActor(o, "hah"), "hah")
     a = objects.Actor.createFor(o)
     self.assertEquals(iimaginary.IActor(o, None), a)