Пример #1
0
    def testDirectionalMovement(self):
        # A couple tweaks to state to make the test simpler
        self.observer.location = None
        self.location.description = None

        oldRoom = self.location
        allDirections = [
            "northwest", "north", "northeast", "east", "west", "southwest",
            "south", "southeast"
        ]
        for d in allDirections[:len(allDirections) / 2]:
            room = objects.Thing(store=self.store, name=u"destination")
            objects.Container.createFor(room, capacity=1000)
            objects.Exit.link(oldRoom, room, unicode(d, 'ascii'))
            oldRoom = room

        for d, rd in zip(allDirections, reversed(allDirections)):
            self._test(
                d,
                [
                    E("[ ") + ".*" + E(" ]"),  # Not testing room description
                    E("( ") + ".*" +
                    E(" )"
                      ),  # Just do enough to make sure it was not an error.
                    ""
                ])
Пример #2
0
    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()
Пример #3
0
 def test_exits(self):
     objects.Exit.link(self.location, self.location, u"north")
     self._test("look here", [
         E("[ Test Location ]"),
         E("( north south )"),
         E("Location for testing."), "Here, you see Observer Player."
     ])
Пример #4
0
    def test_goThroughDirectionAliases(self):
        """
        The I{go} action moves the player through an exit in the specified
        direction even when that direction is an alias.
        """
        self._test(
            "go w",
            ["You can't go that way."])
        self._test(
            "w",
            ["You can't go that way."])

        room = objects.Thing(store=self.store, name=u"destination")
        objects.Container.createFor(room, capacity=1000)
        objects.Exit.link(self.location, room, u"west")

        self._test(
            "w",
            [E("[ destination ]"),
             E("( east )"),
             ""],
            ["Test Player leaves west."])

        self._test(
            "n",
            ["You can't go that way."])
        self._test(
            "go e",
            [E("[ Test Location ]"),
             E("( west )"),
             "Location for testing.",
             "Here, you see Observer Player."],
            ["Test Player arrives from the west."])
Пример #5
0
 def test_goThroughOneWayExit(self):
     """
     Going through a one-way exit with a known direction will announce that
     the player arrived from that direction; with an unknown direction it
     will simply announce that they have arrived.
     """
     secretRoom = objects.Thing(store=self.store, name=u'Secret Room!')
     objects.Container.createFor(secretRoom, capacity=1000)
     myExit = objects.Exit(store=self.store, fromLocation=secretRoom,
                           toLocation=self.location, name=u'north')
     self.player.moveTo(secretRoom)
     self._test(
         "north",
         [E("[ Test Location ]"),
          "Location for testing.",
          "Here, you see Observer Player."],
         ["Test Player arrives from the south."])
     self.player.moveTo(secretRoom)
     myExit.name = u'elsewhere'
     self.assertCommandOutput(
         "go elsewhere",
         [E("[ Test Location ]"),
          "Location for testing.",
          "Here, you see Observer Player."],
         ["Test Player arrives."])
Пример #6
0
 def test_equipment(self):
     self.observer.moveTo(None)
     self._test(u"create a shirt named t-shirt", [u"You create a t-shirt."])
     self._test(u"wear t-shirt", [u"You put on the t-shirt."])
     self._test(u"look",
                [E(u"[ Test Location ]"),
                 E(u"Location for testing.")])
Пример #7
0
    def testLook(self):
        self._test("look", [
            E("[ Test Location ]"), "Location for testing.", "Observer Player"
        ])

        self._test("look here", [
            E("[ Test Location ]"), "Location for testing.", "Observer Player"
        ])

        objects.Exit.link(self.location, self.location, u"north")
        self._test("look here", [
            E("[ Test Location ]"),
            E("( north south )"), "Location for testing.", "Observer Player"
        ])

        self._test(
            "look me",
            [E("[ Test Player ]"), "Test Player is great.", "She is naked."])

        self._test(
            "look at me",
            [E("[ Test Player ]"), "Test Player is great.", "She is naked."])

        self._test("look at Observer Player", [
            E("[ Observer Player ]"), "Observer Player is great.",
            "She is naked."
        ], ["Test Player looks at you."])

        o = objects.Thing(store=self.store, name=u"foo")
        iimaginary.IContainer(self.location).add(o)
        self._test("look at foo", [E("[ foo ]")])

        self._test("look at bar", ["You don't see that."])
Пример #8
0
 def test_bearBlindness(self):
     """
     If I cast a spell on you which makes you unable to see bears, you
     should not see a bear in the room with you when you look at the room
     around you.
     """
     bear = objects.Thing(store=self.store,
                          name=u"Bear",
                          location=self.location)
     BearBlindness(store=self.store, thing=self.player,
                   bear=bear).applyEnhancement()
     self._test("look here", [
         E("[ Test Location ]"),
         E("Location for testing."), "Here, you see Observer Player."
     ])
Пример #9
0
 def test_takeAndLeave(self):
     """
     You can't leave the room if you're holding the ball that's tied to it.
     """
     self.assertCommandOutput("take ball", ["You take a ball."],
                              ["Test Player takes a ball."])
     self.assertCommandOutput(
         "go north", ["You can't move, you're still holding a ball."],
         ["Test Player struggles with a ball."])
     self.assertCommandOutput("drop ball", ["You drop the ball."],
                              ["Test Player drops a ball."])
     self.assertCommandOutput(
         "go north",
         [E("[ elsewhere ]"), E("( south )"), ""],
         ["Test Player leaves north."])
Пример #10
0
 def test_lookAt(self):
     """
     You can see the contents within a glass box by looking at the box.
     """
     self.assertCommandOutput(
         "look at box",
         [E("[ box ]"), "The system under test.", "It contains a ball."])
Пример #11
0
    def testGo(self):
        self._test("go west", ["You can't go that way."])
        self._test("west", ["You can't go that way."])

        room = objects.Thing(store=self.store, name=u"destination")
        objects.Container.createFor(room, capacity=1000)
        objects.Exit.link(self.location, room, u"west")

        self._test("west", [E("[ destination ]"),
                            E("( east )"), ""], ["Test Player leaves west."])

        self._test("north", ["You can't go that way."])
        self._test("go east", [
            E("[ Test Location ]"),
            E("( west )"), "Location for testing.", "Observer Player"
        ], ["Test Player arrives from the west."])
Пример #12
0
 def test_childObject(self):
     o = objects.Thing(store=self.store, name=u"foo")
     self.playerContainer.add(o)
     self._test("look", [
         E(u"[ Test Location ]"), u"Location for testing.",
         u"Here, you see Observer Player."
     ])
Пример #13
0
 def test_cousinObject(self):
     o = objects.Thing(store=self.store, name=u"foo")
     iimaginary.IContainer(self.observer).add(o)
     self._test("look", [
         E(u"[ Test Location ]"), u"Location for testing.",
         u"Here, you see Observer Player."
     ])
Пример #14
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)
Пример #15
0
 def test_enterBox(self):
     """
     I should be able to enter the box.
     """
     self.assertCommandOutput('enter box', [
         E('[ Test Location ]'), 'Location for testing.',
         'Here, you see Observer Player and a box.'
     ], ['Test Player leaves into the box.'])
Пример #16
0
    def testProperlyDressed(self):
        self.createPants()
        self._test("create underwear named 'pair of polka dot underwear'",
                   ["You create a pair of polka dot underwear."],
                   ["Test Player creates a pair of polka dot underwear."])
        self._test("wear 'pair of polka dot underwear'",
                   ["You put on the pair of polka dot underwear."],
                   ["Test Player puts on a pair of polka dot underwear."])

        self._test("wear 'pair of blue pants'",
                   ["You put on the pair of blue pants."],
                   ["Test Player puts on a pair of blue pants."])
        self._test("look me", [
            E("[ Test Player ]"),
            E("Test Player is great."),
            E("It is wearing a pair of blue pants.")
        ])
Пример #17
0
 def testTooBulky(self):
     self.createPants()
     self._test("create pants named 'pair of overalls'",
                ["You create a pair of overalls."],
                ["Test Player creates a pair of overalls."])
     self._test("wear 'pair of overalls'",
                ["You put on the pair of overalls."],
                ["Test Player puts on a pair of overalls."])
     self._test("wear 'pair of blue pants'", [
         "The pair of overalls you are already wearing is too "
         "bulky for you to do that."
     ], ["Test Player wrestles with basic personal problems."])
     self._test("look me", [
         E("[ Test Player ]"),
         E("Test Player is great."),
         E("It is wearing a pair of overalls."),
         E("It is carrying a pair of blue pants."),
     ])
Пример #18
0
    def testProperlyDressed(self):
        self._test("create pants named 'pair of daisy dukes'",
                   ["You create a pair of daisy dukes."],
                   ["Test Player creates a pair of daisy dukes."])
        self._test("create underwear named 'pair of lace panties'",
                   ["You create a pair of lace panties."],
                   ["Test Player creates a pair of lace panties."])
        self._test("wear 'pair of lace panties'",
                   ["You put on the pair of lace panties."],
                   ["Test Player puts on a pair of lace panties."])

        self._test("wear 'pair of daisy dukes'",
                   ["You put on the pair of daisy dukes."],
                   ["Test Player puts on a pair of daisy dukes."])
        self._test("look me", [
            E("[ Test Player ]"),
            E("Test Player is great."),
            E("She is wearing a pair of daisy dukes.")
        ])
Пример #19
0
 def test_exitBox(self):
     """
     I should be able to exit the box.
     """
     self.player.moveTo(self.container)
     self.assertCommandOutput('exit out', [
         E('[ Test Location ]'), 'Location for testing.',
         'Here, you see Observer Player and a box.'
     ], ['Test Player leaves out of the box.'])
     self.assertEquals(self.player.location, self.location)
Пример #20
0
 def test_scrutinizeNonContainer(self):
     """
     The scrutinize action produces results for a thing which is not a
     container.
     """
     o = objects.Thing(store=self.store, name=u"foo")
     iimaginary.IContainer(self.location).add(o)
     self._test(
         "scrutinize foo",
         [E(u"('Thing',"),
          E(u" {'description': u'',"),
          E(u"  'gender': 3,"),
          E(u"  'location': Thing(description=u'Location for testing.', "
            "gender=3, location=None, name=u'Test Location', portable="
            "True, proper=True, weight=1, storeID=") +
          STOREID + E(")@0x") + PTR + E(","),
          E(u"  'name': u'foo',"),
          E(u"  'portable': True,"),
          E(u"  'proper': False,"),
          E(u"  'weight': 1})")])
Пример #21
0
 def test_goDoesntJumpOverExits(self):
     """
     You can't go through an exit without passing through exits which lead
     to it.  Going through an exit named 'east' will only work if it is east
     of your I{present} location, even if it is easily reachable from where
     you stand.
     """
     northRoom = objects.Thing(store=self.store, name=u'Northerly')
     eastRoom = objects.Thing(store=self.store, name=u'Easterly')
     for room in northRoom, eastRoom:
         objects.Container.createFor(room, capacity=1000)
     objects.Exit.link(self.location, northRoom, u'north', distance=0.1)
     objects.Exit.link(northRoom, eastRoom, u'east', distance=0.1)
     self.assertCommandOutput("go east", [E("You can't go that way.")], [])
Пример #22
0
 def testInaccessibleGarment(self):
     self.createPants()
     self._test("create underwear named 'pair of polka dot underwear'",
                ["You create a pair of polka dot underwear."],
                ["Test Player creates a pair of polka dot underwear."])
     self._test("wear 'pair of polka dot underwear'",
                ["You put on the pair of polka dot underwear."],
                ["Test Player puts on a pair of polka dot underwear."])
     self._test("wear 'pair of blue pants'",
                ["You put on the pair of blue pants."],
                ["Test Player puts on a pair of blue pants."])
     self._test("remove 'pair of polka dot underwear'", [
         E("You cannot take off the pair of polka dot underwear "
           "because you are wearing a pair of blue pants.")
     ], ["Test Player gets a dumb look on its face."])
Пример #23
0
    def testSearch(self):
        self._test("search self", [
            E("[ Test Player ]"), "Test Player is great.", "She is naked.", ""
        ])

        self._test("search me", [
            E("[ Test Player ]"), "Test Player is great.", "She is naked.", ""
        ])

        self._test("search here", [
            E("[ Test Location ]"), "Location for testing.", "Observer Player",
            ""
        ])

        self._test("search 'Test Player'", [
            E("[ Test Player ]"), "Test Player is great.", "She is naked.", ""
        ])

        self._test('search "Observer Player"', [
            E("[ Observer Player ]"), "Observer Player is great.",
            "She is naked.", ""
        ])

        self._test("search blub", [""])
Пример #24
0
 def testInaccessibleGarment(self):
     self._test("create pants named 'pair of daisy dukes'",
                ["You create a pair of daisy dukes."],
                ["Test Player creates a pair of daisy dukes."])
     self._test("create underwear named 'pair of lace panties'",
                ["You create a pair of lace panties."],
                ["Test Player creates a pair of lace panties."])
     self._test("wear 'pair of lace panties'",
                ["You put on the pair of lace panties."],
                ["Test Player puts on a pair of lace panties."])
     self._test("wear 'pair of daisy dukes'",
                ["You put on the pair of daisy dukes."],
                ["Test Player puts on a pair of daisy dukes."])
     self._test("remove 'pair of lace panties'", [
         E("You cannot take off the pair of lace panties because you are wearing a pair of daisy dukes."
           )
     ], ["Test Player gets a dumb look on her face."])
Пример #25
0
 def test_siblingObject(self):
     self._test("look", [
         E(u"[ Test Location ]"), u"Location for testing.",
         u"Here, you see Observer Player."
     ])
Пример #26
0
 def test_emptyLocation(self):
     iimaginary.IContainer(self.location).remove(self.observer)
     self._test(u"look", [
         E(u"[ Test Location ]"),
         u"Location for testing.",
     ])
Пример #27
0
    def test_scrutinize(self):
        """
        The scrutinize action takes a thing as a target and displays a lot of
        details about its internal state and construction.
        """
        self._test(
            "scrutinize me",
            [E("('Thing',"),
             E(" {'contents': [],"),
             E("  'description': u'',"),
             E("  'gender': 2,"),
             E("  'location': Thing(description=u'Location for testing.', "
               "gender=3, location=None, name=u'Test Location', portable=True, "
               "proper=True, weight=1, storeID=") + STOREID + E(")@0x") + PTR
               + E(","),
             E("  'name': u'Test Player',"),
             E("  'portable': True,"),
             E("  'proper': True,"),
             E("  'weight': 100})"),
             ])

        self._test(
            "scrutinize here",
            [E("('Thing',"),
             E(" {'contents': [Thing(description=u'', gender=2, location="
               "reference(") +
             STOREID + E("), name=u'Test Player', portable=True, proper="
                         "True, weight=100, storeID=") +
             STOREID + E(")@0x") + PTR + E(","),
             E("               Thing(description=u'', gender=2, location="
               "reference(") +
             STOREID + E("), name=u'Observer Player', portable=True, "
                         "proper=True, weight=100, storeID=") +
             STOREID + E(")@0x") + PTR + E("],"),
             E("  'description': u'Location for testing.',"),
             E("  'gender': 3,"),
             E("  'location': None,"),
             E("  'name': u'Test Location',"),
             E("  'portable': True,"),
             E("  'proper': True,"),
             E("  'weight': 1})")])
Пример #28
0
    def testInvalidAttacks(self):
        self._test("hit here", [E("Who's that?")], [])

        obj = objects.Thing(store=self.store, name=u"quiche")
        obj.moveTo(self.location)
        self._test("hit quiche", [E("Who's that?")], [])
Пример #29
0
 def test_lookAtThing(self):
     o = objects.Thing(store=self.store, name=u"foo")
     iimaginary.IContainer(self.location).add(o)
     self._test("look at foo", [E("[ foo ]")])
Пример #30
0
 def test_lookAtAnother(self):
     self._test("look at Observer Player", [
         E("[ Observer Player ]"), "Observer Player is great.",
         "She is naked."
     ], ["Test Player looks at you."])