コード例 #1
0
 def setUp(self):
     self.store = store.Store()
     self.containmentCore = objects.Thing(store=self.store,
                                          name=u"container")
     self.container = objects.Container.createFor(self.containmentCore,
                                                  capacity=1)
     self.object = objects.Thing(store=self.store, name=u"object")
コード例 #2
0
    def testGet(self):
        # Try to get something that does not exist
        self._test(
            "get foobar",
            ["Nothing like that around here."])

        # Try to get yourself
        self._test(
            "get self",
            ["You cannot take Test Player."])
        self.assertEquals(self.player.location, self.location)

        # Try to get the location
        self._test(
            "get here",
            ["You cannot take Test Location."])
        self.assertEquals(self.location.location, None)

        # Make an object and try to get it
        o = objects.Thing(store=self.store, name=u"foo")
        iimaginary.IContainer(self.location).add(o)
        self._test(
            "get foo",
            ["You take a foo."],
            ["Test Player takes a foo."])
        self.assertEquals(o.location, self.player)

        # Try to get the observer
        self._test(
            "get 'Observer Player'",
            ["Observer Player is too heavy to pick up."],
            ["Test Player tries to pick you up, but fails."])
        self.assertEquals(self.observer.location, self.location)

        # Container stuff
        self._test(
            "get baz from bar",
            ["Nothing like that around here."])

        c = objects.Thing(store=self.store, name=u"bar")
        cContainer = objects.Container.createFor(c, capacity=1)

        iimaginary.IContainer(self.location).add(c)
        o = objects.Thing(store=self.store, name=u"baz")
        cContainer.add(o)
        self._test(
            "get baz from bar",
            ["You take a baz from the bar."],
            ["Test Player takes a baz from the bar."])
        self.assertEquals(o.location, self.player)

        # Can't get things from a closed container
        o.moveTo(c)
        cContainer.closed = True
        self._test(
            "get baz from bar",
            ["Nothing like that around here."],
            [])
        self.assertEquals(o.location, c)
        self.assertEquals(list(cContainer.getContents()), [o])
コード例 #3
0
    def testInventory(self):
        # There ain't no stuff
        self._test(
            "inventory",
            ["Inventory:"])

        playerContainer = iimaginary.IContainer(self.player)

        # Give 'em something and make sure
        # they show up
        playerContainer.add(objects.Thing(store=self.store, name=u"foobar"))
        self._test(
            "inventory",
            ["Inventory:",
             "foobar"])

        # Give 'em a couple more things
        playerContainer.add(objects.Thing(store=self.store, name=u"barbaz"))
        playerContainer.add(objects.Thing(store=self.store, name=u"barbaz"))
        self._test(
            "inventory",
            ["Inventory:",
             "foobar",
             "barbaz",
             "barbaz"])
コード例 #4
0
ファイル: test_put.py プロジェクト: zeeneddie/imaginary
 def setUp(self):
     r = commandutils.CommandTestCaseMixin.setUp(self)
     self.object = objects.Thing(store=self.store, name=u"foo")
     self.object.moveTo(self.player)
     self.container = objects.Thing(store=self.store, name=u"bar")
     self.containerContainer = objects.Container.createFor(self.container, capacity=1)
     self.container.moveTo(self.location)
     return r
コード例 #5
0
 def testMoving(self):
     obj = objects.Thing(store=self.store, name=u"DOG")
     room = objects.Thing(store=self.store, name=u"HOUSE")
     objects.Container.createFor(room, capacity=1000)
     obj.moveTo(room)
     self.assertIdentical(obj.location, room)
     obj.moveTo(room)
     self.assertIdentical(obj.location, room)
コード例 #6
0
 def setUp(self):
     self.store = store.Store()
     self.retained = []
     obj = objects.Thing(store=self.store, name=u"generic object")
     room = objects.Thing(store=self.store, name=u"room")
     objects.Container.createFor(room, capacity=1000)
     obj.moveTo(room)
     self.obj = obj
     self.room = room
コード例 #7
0
 def setUp(self):
     self.store = store.Store()
     self.room = objects.Thing(store=self.store, name=u'room')
     roomContainer = objects.Container.createFor(self.room, capacity=456)
     self.box = objects.Thing(store=self.store, name=u"box")
     self.container = objects.Container.createFor(self.box, capacity=123)
     self.observer = objects.Thing(store=self.store, name=u"observer")
     self.observer.moveTo(roomContainer)
     self.box.moveTo(roomContainer)
     self.concept = objects.ExpressContents(
         self.container, list(self.observer.idea.obtain(Paths())))
コード例 #8
0
    def testDestroy(self):
        obj = objects.Thing(store=self.store, name=u"x")
        obj.destroy()

        room = objects.Thing(store=self.store, name=u"test location")
        locContainer = objects.Container.createFor(room, capacity=1000)
        obj = objects.Thing(store=self.store, name=u"y")
        obj.moveTo(room)

        obj.destroy()
        self.assertIdentical(obj.location, None)
        self.assertEquals(list(locContainer.getContents()), [])
コード例 #9
0
    def setUp(self):
        self.store = store.Store()
        self.location = objects.Thing(store=self.store, name=u"Dark Room")
        objects.Container.createFor(self.location, capacity=1000)

        objects.LocationLighting.createFor(self.location, candelas=0)

        self.rock = objects.Thing(store=self.store, name=u"Rock")

        self.observer = objects.Thing(store=self.store, name=u"Observer")

        self.rock.moveTo(self.location)
        self.observer.moveTo(self.location)
コード例 #10
0
    def setUp(self):
        self.store = store.Store()

        self.location = objects.Thing(store=self.store, name=u"Place")
        self.locationContainer = objects.Container.createFor(self.location,
                                                             capacity=1000)

        self.alice = objects.Thing(store=self.store, name=u"Alice")
        self.actor = objects.Actor.createFor(self.alice)

        self.alice.moveTo(self.location)

        self.intelligence = commandutils.MockIntelligence(store=self.store)
        self.actor.setEnduringIntelligence(self.intelligence)
コード例 #11
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.")], [])
コード例 #12
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()

        closet = objects.Thing(store=self.store, name=u"Closet")
        closetContainer = objects.Container.createFor(closet, capacity=500)

        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(self.mouseName)],
            ["Test Player leaves north."])

        clock.advance(mousehood.challengeInterval)

        self._test(None, [self.speechPattern])
コード例 #13
0
    def testLookingOut(self):
        """
        Test that when findProviders is called on an observer in a dark
        location, objects in nearby illuminated rooms are returned.
        """
        nearby = objects.Thing(store=self.store, name=u"other room")
        objects.Container.createFor(nearby, capacity=1000)
        ball = objects.Thing(store=self.store, name=u"ball")
        ball.moveTo(nearby)

        objects.Exit.link(self.location, nearby, u"west")

        found = list(self.observer.findProviders(iimaginary.IVisible, 3))
        self.assertDarkRoom(found[0])
        self.assertEquals(found[1:], [nearby, ball])
        self.assertEquals(len(found), 3)
コード例 #14
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 = objects.Thing(store=self.store, name=u"Mouse Hole")
        objects.Container.createFor(elsewhere, capacity=1000)

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

        mouse.moveTo(elsewhere)

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

        clock.advance(0)
        self._test(None, ["SQUEAK!"])
コード例 #15
0
    def testMovementArrivalEvent(self):
        """
        Test that when a Thing is moved to a location, an arrival event is
        broadcast to that location.
        """
        destination = objects.Thing(store=self.store, name=u'ELSEWHERE')
        objects.Container.createFor(destination, capacity=1000)

        self.observer.moveTo(destination,
                             arrivalEventFactory=events.MovementArrivalEvent)

        evts = self.intelligence.events
        self.assertEquals(len(evts), 1)
        self.failUnless(isinstance(evts[0], events.MovementArrivalEvent))
        self.assertIdentical(evts[0].thing, self.observer)
        self.assertIdentical(evts[0].location, destination)
        evts[:] = []

        self.obj.moveTo(destination,
                        arrivalEventFactory=events.MovementArrivalEvent)

        evts = self.intelligence.events
        self.assertEquals(len(evts), 1)
        self.failUnless(isinstance(evts[0], events.ArrivalEvent))
        self.assertIdentical(evts[0].location, destination)
        self.assertIdentical(evts[0].thing, self.obj)
コード例 #16
0
ファイル: test_actor.py プロジェクト: zeeneddie/imaginary
 def testExperience(self):
     o = objects.Thing(store=self.store, name=u"hitty")
     a = objects.Actor.createFor(o)
     self.assertEquals(a.experience, 0)
     a.gainExperience(1100)
     self.assertEquals(a.experience, 1100)
     self.assertEquals(a.level, 10)
コード例 #17
0
 def createMouse(**kw):
     store = kw['store']
     mouse = objects.Thing(**kw)
     mouseActor = objects.Actor.createFor(mouse)
     mousehood = mouseIntelligenceFactory(store=store)
     mouseActor.setEnduringIntelligence(mousehood)
     return mouse
コード例 #18
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()
コード例 #19
0
ファイル: test_look.py プロジェクト: zeeneddie/imaginary
 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."
     ])
コード例 #20
0
    def test_directionalMovement(self):
        """
        You can move through exits in standard directions by just specifying
        the direction.
        """
        # 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.
                 ""])
        shortDirections = ["nw", "n", "ne", "e", "w", "sw", "s", "se"]
        for d, rd in zip(shortDirections, reversed(shortDirections)):
            self._test(
                d,
                [E("[ ") + ".*" + E(" ]"), # Not testing room description
                 E("( ") + ".*" + E(" )"), # Just do enough to make sure it was not an error.
                 ""])
コード例 #21
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."])
コード例 #22
0
    def setUp(self):
        """
        Set up a store with a location, a player and an observer.
        """
        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, origin=self.location)
        self.player = self.world.create(u"Test Player",
                                        gender=language.Gender.FEMALE)
        self.playerContainer = iimaginary.IContainer(self.player)
        self.playerWrapper = player.Player(self.player)

        self.playerWrapper.useColors = False
        locContainer.add(self.player)
        self.transport = StringTransport()
        self.playerWrapper.setProtocol(PlayerProtocol(self.transport))

        self.observer = self.world.create(u"Observer Player",
                                          gender=language.Gender.FEMALE)
        self.observerWrapper = player.Player(self.observer)
        locContainer.add(self.observer)
        self.otransport = StringTransport()
        self.observerWrapper.setProtocol(PlayerProtocol(self.otransport))

        # Clear the transport, since we don't care about the observer
        # arrival event.
        self.transport.clear()
コード例 #23
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."])
コード例 #24
0
    def testBury(self):
        self._test("bury south", ["There isn't an exit in that direction."])
        self.assertEquals(
            list(iimaginary.IContainer(self.location).getExits()), [])

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

        self._test("bury south", ["It's gone."],
                   ["Test Player destroyed the exit to destination."])

        self.assertEquals(
            list(iimaginary.IContainer(self.location).getExits()), [])

        self.assertEquals(list(iimaginary.IContainer(room).getExits()), [])

        objects.Exit.link(self.location, room, u'south')
        self.observer.moveTo(room)

        self._test("bury south", ["It's gone."],
                   ["The exit to Test Location crumbles and disappears."])
        self.assertEquals(
            list(iimaginary.IContainer(self.location).getExits()), [])
        self.assertEquals(list(iimaginary.IContainer(room).getExits()), [])
コード例 #25
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."])
コード例 #26
0
ファイル: test_look.py プロジェクト: zeeneddie/imaginary
 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."
     ])
コード例 #27
0
    def setUp(self):
        self.store = store.Store()
        obj = objects.Thing(store=self.store, name=u"DOG")
        room = objects.Thing(store=self.store, name=u"HOUSE")
        objects.Container.createFor(room, capacity=1000)
        obj.moveTo(room)

        observer = objects.Thing(store=self.store, name=u"OBSERVER")
        actor = objects.Actor.createFor(observer)
        intelligence = commandutils.MockEphemeralIntelligence()
        actor.setEphemeralIntelligence(intelligence)

        self.obj = obj
        self.room = room
        self.observer = observer
        self.intelligence = intelligence
        self.actor = actor
コード例 #28
0
    def testDrop(self):
        self._test("drop foo", ["Nothing like that around here."])

        o = objects.Thing(store=self.store, name=u"bar")
        iimaginary.IContainer(self.player).add(o)
        self._test("drop bar", ["You drop the bar."],
                   ["Test Player drops a bar."])
        self.assertEquals(o.location, self.location)
コード例 #29
0
 def testNonPortable(self):
     """
     Test that the C{portable} flag is respected and prevents movement
     between locations.
     """
     obj = objects.Thing(store=self.store, name=u"mountain")
     obj.portable = False
     room = objects.Thing(store=self.store, name=u"place")
     objects.Container.createFor(room, capacity=1000)
     obj.moveTo(room)
     elsewhere = objects.Thing(store=self.store, name=u"different place")
     container = objects.Container.createFor(elsewhere, capacity=1000)
     self.assertRaises(eimaginary.CannotMove, obj.moveTo, elsewhere)
     self.assertIdentical(obj.location, room)
     self.assertEquals(list(iimaginary.IContainer(room).getContents()),
                       [obj])
     self.assertEquals(list(container.getContents()), [])
コード例 #30
0
    def test_parameterizedArrivalDefaultsNone(self):
        """
        The default should be for moveTo not to broadcast an event.
        """
        destination = objects.Thing(store=self.store, name=u'ELSEWHERE')
        objects.Container.createFor(destination, capacity=1000)

        self.observer.moveTo(destination)
        self.assertEquals(self.intelligence.events, [])