Пример #1
0
    def create(self, name, **kw):
        """
        Make a new character L{Thing} with the given name and return it.

        @type name: C{unicode}
        @rtype: L{Thing}
        """
        if self.origin is None:
            self.origin = Thing(store=self.store, name=u"The Place")
            Container.createFor(self.origin, capacity=1000)

        if 'proper' not in kw:
            kw['proper'] = True

        character = Thing(store=self.store, weight=100,
                          name=name, **kw)
        Container.createFor(
            character, capacity=10,
            contentsTemplate=u"{subject:pronoun} is carrying {contents}.")
        Actor.createFor(character)

        # Unfortunately, world -> garments -> creation -> action ->
        # world. See #2906. -exarkun
        from imaginary.garments import Wearer
        Wearer.createFor(character)

        character.moveTo(
            self.origin,
            lambda player: MovementArrivalEvent(
                thing=player, origin=None, direction=None))
        return character
Пример #2
0
    def create(self, name, **kw):
        """
        Make a new character L{Thing} with the given name and return it.

        @type name: C{unicode}
        @rtype: L{Thing}
        """
        if self.origin is None:
            self.origin = Thing(store=self.store, name=u"The Place")
            Container.createFor(self.origin, capacity=1000)

        character = Thing(store=self.store,
                          weight=100,
                          name=name,
                          proper=True,
                          **kw)
        Container.createFor(character, capacity=10)
        Actor.createFor(character)

        # Unfortunately, world -> garments -> creation -> action ->
        # world. See #2906. -exarkun
        from imaginary.garments import Wearer
        Wearer.createFor(character)

        character.moveTo(
            self.origin, lambda player: MovementArrivalEvent(
                thing=player, origin=None, direction=None))
        return character
Пример #3
0
 def setUp(self):
     """
     Set Up.
     """
     CommandTestCaseMixin.setUp(self)
     self.squeaker = Thing(store=self.store, name=u"squeaker")
     self.squeaker.moveTo(self.location)
     self.squeakification = Squeaker.createFor(self.squeaker)
Пример #4
0
 def setUp(self):
     """
     Tether a ball to the room.
     """
     CommandTestCaseMixin.setUp(self)
     self.ball = Thing(store=self.store, name=u'ball')
     self.ball.moveTo(self.location)
     self.tether = Tether.createFor(self.ball, to=self.location)
     self.otherPlace = Thing(store=self.store, name=u'elsewhere')
     Container.createFor(self.otherPlace, capacity=1000)
     Exit.link(self.location, self.otherPlace, u'north')
Пример #5
0
 def test_allTiedUp(self):
     """
     If you're tied to a chair, you can't leave.
     """
     chairThing = Thing(store=self.store, name=u'chair')
     chairThing.moveTo(self.location)
     chair = Chair.createFor(chairThing)
     self.assertCommandOutput("sit chair", ["You sit in the chair."],
                              ["Test Player sits in the chair."])
     Tether.createFor(self.player, to=chairThing)
     self.assertCommandOutput("stand up",
                              ["You can't move, you're tied to a chair."],
                              ["Test Player struggles."])
Пример #6
0
 def setUp(self):
     """
     Create a room with a L{GlassBox} in it, which itself contains a ball.
     """
     CommandTestCaseMixin.setUp(self)
     self.box = Thing(store=self.store, name=u'box',
                      description=u'The system under test.')
     self.ball = Thing(store=self.store, name=u'ball',
                       description=u'an interesting object')
     self.container = Container.createFor(self.box)
     GlassBox.createFor(self.box)
     self.ball.moveTo(self.box)
     self.box.moveTo(self.location)
     self.container.closed = True
Пример #7
0
def fourForms(function):
    """
    Generate four noun declensions for the given L{textNounForm} function.

    @rtype: four noun declensions in the order female, male, indeterminate, and
        neuter/impersonal gender.

    @rtype: a 4-L{tuple} of L{unicode}
    """
    alice = Thing(name=u"alice", gender=Gender.FEMALE)
    bob = Thing(name=u"bob", gender=Gender.MALE)
    pat = Thing(name=u"pat", gender=Gender.INDETERMINATE)
    killbot9000 = Thing(name=u"killbot", gender=Gender.NEUTER)
    return tuple(map(function, [alice, bob, killbot9000, pat]))
Пример #8
0
 def test_allTiedUp(self):
     """
     If you're tied to a chair, you can't leave.
     """
     chairThing = Thing(store=self.store, name=u'chair')
     chairThing.moveTo(self.location)
     chair = Chair.createFor(chairThing)
     self.assertCommandOutput("sit chair",
                              ["You sit in the chair."],
                              ["Test Player sits in the chair."])
     Tether.createFor(self.player, to=chairThing)
     self.assertCommandOutput(
         "stand up",
         ["You can't move, you're tied to a chair."],
         ["Test Player struggles."])
Пример #9
0
    def test_squeakyContainer(self):
        """
        If a container is squeaky, that shouldn't interfere with its function
        as a container.  (i.e. let's make sure that links keep working even
        though we're using an annotator here.)
        """
        cont = Container.createFor(self.squeaker)

        mcguffin = Thing(store=self.store, name=u"mcguffin")
        mcguffin.moveTo(cont)

        self.assertCommandOutput(
            "take mcguffin from squeaker",
            ["You take a mcguffin from the squeaker."],
            ["Test Player takes a mcguffin from the squeaker."])
Пример #10
0
 def setUp(self):
     """
     Create a room with a L{GlassBox} in it, which itself contains a ball.
     """
     CommandTestCaseMixin.setUp(self)
     self.box = Thing(store=self.store,
                      name=u'box',
                      description=u'The system under test.')
     self.ball = Thing(store=self.store,
                       name=u'ball',
                       description=u'an interesting object')
     self.container = Container.createFor(self.box)
     GlassBox.createFor(self.box)
     self.ball.moveTo(self.box)
     self.box.moveTo(self.location)
     self.container.closed = True
Пример #11
0
 def setUp(self):
     """
     Create a room, with a dude in it, and a chair he can sit in.
     """
     CommandTestCaseMixin.setUp(self)
     self.chairThing = Thing(store=self.store, name=u"chair")
     self.chairThing.moveTo(self.location)
     self.chair = Chair.createFor(self.chairThing)
Пример #12
0
    def test_arrivalEvent(self):
        """
        Test that when a thing is dropped, an ArrivalEvent instance is
        broadcast to the room it is dropped into.
        """
        st = Store()

        player, actor, intelligence = createPlayer(st, u"Foo")
        place = Thing(store=st, name=u"soko")
        player.moveTo(Container.createFor(place, capacity=1000))

        bauble = Thing(store=st, name=u"bauble")
        bauble.moveTo(player)

        Drop().runEventTransaction(player, None, dict(target=bauble.name))
        self.assertEquals(len([concept for concept
                               in intelligence.concepts
                               if isinstance(concept, ArrivalEvent)]), 1)
Пример #13
0
 def test_multiples(self):
     """
     Multiple substitution markers may be used in a single template.
     """
     another = Thing(name=u"bob", gender=Gender.FEMALE)
     template = ConceptTemplate(u"{a:name} hits {b:name}.")
     self.assertEqual(
         u"alice hits bob.",
         self.expandToText(template, dict(a=self.thing, b=another)))
Пример #14
0
 def test_adjacent(self):
     """
     Adjacent substitution markers are expanded without introducing
     extraneous intervening characters.
     """
     another = Thing(name=u"bob", gender=Gender.FEMALE)
     template = ConceptTemplate(u"{a:name}{b:name}")
     self.assertEqual(
         u"alicebob",
         self.expandToText(template, dict(a=self.thing, b=another)))
Пример #15
0
class SqueakTest(CommandTestCaseMixin, TestCase):
    """
    Squeak Test.
    """

    def setUp(self):
        """
        Set Up.
        """
        CommandTestCaseMixin.setUp(self)
        self.squeaker = Thing(store=self.store, name=u"squeaker")
        self.squeaker.moveTo(self.location)
        self.squeakification = Squeaker.createFor(self.squeaker)


    def test_itSqueaks(self):
        """
        Picking up a squeaky thing makes it emit a squeak.
        """
        self.assertCommandOutput(
            "take squeaker",
            ["You take a squeaker.",
             "A squeaker emits a faint squeak."],
            ["Test Player takes a squeaker.",
             "A squeaker emits a faint squeak."])


    def test_squeakyContainer(self):
        """
        If a container is squeaky, that shouldn't interfere with its function
        as a container.  (i.e. let's make sure that links keep working even
        though we're using an annotator here.)
        """
        cont = Container.createFor(self.squeaker)

        mcguffin = Thing(store=self.store, name=u"mcguffin")
        mcguffin.moveTo(cont)

        self.assertCommandOutput(
            "take mcguffin from squeaker",
            ["You take a mcguffin from the squeaker."],
            ["Test Player takes a mcguffin from the squeaker."])
Пример #16
0
 def setUp(self):
     """
     Tether a ball to the room.
     """
     CommandTestCaseMixin.setUp(self)
     self.ball = Thing(store=self.store, name=u'ball')
     self.ball.moveTo(self.location)
     self.tether = Tether.createFor(self.ball, to=self.location)
     self.otherPlace = Thing(store=self.store, name=u'elsewhere')
     Container.createFor(self.otherPlace, capacity=1000)
     Exit.link(self.location, self.otherPlace, u'north')
Пример #17
0
    def test_arrivalEvent(self):
        """
        Test that when a thing is dropped, an ArrivalEvent instance is
        broadcast to the room it is dropped into.
        """
        st = Store()

        player, actor, intelligence = createPlayer(st, u"Foo")
        place = Thing(store=st, name=u"soko")
        player.moveTo(Container.createFor(place, capacity=1000))

        bauble = Thing(store=st, name=u"bauble")
        bauble.moveTo(player)

        Drop().runEventTransaction(player, None, dict(target=bauble.name))
        self.assertEquals(
            len([
                concept for concept in intelligence.concepts
                if isinstance(concept, ArrivalEvent)
            ]), 1)
Пример #18
0
 def test_destroyFor(self):
     """
     L{Enhancement.destroyFor} powers down the L{Enhancement} from its
     L{Thing}, and removes it from its store.
     """
     StubEnhancement.createFor(self.thing)
     otherThing = Thing(store=self.store, name=u'test other thing')
     stub2 = StubEnhancement.createFor(otherThing)
     StubEnhancement.destroyFor(self.thing)
     self.assertIdentical(IStubSimulation(self.thing, None), None)
     self.assertEquals([stub2], list(self.store.query(StubEnhancement)))
Пример #19
0
 def test_takeWhenSitting(self):
     """
     When a player is seated, they should still be able to take objects on
     the floor around them.
     """
     self.test_sitDown()
     self.ball = Thing(store=self.store, name=u'ball')
     self.ball.moveTo(self.location)
     self.assertCommandOutput(
         "take ball",
         ["You take a ball."],
         ["Test Player takes a ball."])
Пример #20
0
def world(store):
    def room(name):
        it = Thing(store=store, name=name)
        Container.createFor(it, capacity=1000)
        return it

    world = ImaginaryWorld(store=store, origin=room("The Beginning"))
    protagonist = world.create("An Example Player")
    shirt = createShirt(store=store, name="shirt", location=world.origin)
    pants = createPants(store=store, name="pants", location=world.origin)
    middle = room("The Middle")
    wearer = IClothingWearer(protagonist)
    wearer.putOn(IClothing(shirt))
    wearer.putOn(IClothing(pants))
    Exit.link(world.origin, middle, "north")

    squeakerThing = Thing(name="squeaker", location=middle, store=store)
    Squeaker.createFor(squeakerThing)
    return world
Пример #21
0
class GlassBoxTests(CommandTestCaseMixin, TestCase):
    """
    Tests for L{GlassBox}
    """
    def setUp(self):
        """
        Create a room with a L{GlassBox} in it, which itself contains a ball.
        """
        CommandTestCaseMixin.setUp(self)
        self.box = Thing(store=self.store,
                         name=u'box',
                         description=u'The system under test.')
        self.ball = Thing(store=self.store,
                          name=u'ball',
                          description=u'an interesting object')
        self.container = Container.createFor(self.box)
        GlassBox.createFor(self.box)
        self.ball.moveTo(self.box)
        self.box.moveTo(self.location)
        self.container.closed = True

    def test_lookThrough(self):
        """
        You can see items within a glass box by looking at them directly.
        """
        self.assertCommandOutput("look at ball",
                                 [E("[ ball ]"), "an interesting object"])

    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."])

    def test_take(self):
        """
        You can't take items within a glass box.
        """
        self.assertCommandOutput("get ball",
                                 ["You can't reach through the glass box."])

    def test_openTake(self):
        """
        Taking items from a glass box should work if it's open.
        """
        self.container.closed = False
        self.assertCommandOutput("get ball", ["You take a ball."],
                                 ["Test Player takes a ball."])

    def test_put(self):
        """
        You can't put items into a glass box.
        """
        self.container.closed = False
        self.ball.moveTo(self.location)
        self.container.closed = True
        self.assertCommandOutput("put ball in box", ["The box is closed."])

    def test_whyNot(self):
        """
        A regression test; there was a bug where glass boxes would interfere
        with normal target-acquisition error reporting.
        """
        self.assertCommandOutput("get foobar",
                                 ["Nothing like that around here."])
Пример #22
0
class TetherTest(CommandTestCaseMixin, TestCase):
    """
    A test for tethering an item to its location, such that a player who picks
    it up can't leave until they drop it.
    """
    def setUp(self):
        """
        Tether a ball to the room.
        """
        CommandTestCaseMixin.setUp(self)
        self.ball = Thing(store=self.store, name=u'ball')
        self.ball.moveTo(self.location)
        self.tether = Tether.createFor(self.ball, to=self.location)
        self.otherPlace = Thing(store=self.store, name=u'elsewhere')
        Container.createFor(self.otherPlace, capacity=1000)
        Exit.link(self.location, self.otherPlace, u'north')

    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."])

    def test_allTiedUp(self):
        """
        If you're tied to a chair, you can't leave.
        """
        chairThing = Thing(store=self.store, name=u'chair')
        chairThing.moveTo(self.location)
        chair = Chair.createFor(chairThing)
        self.assertCommandOutput("sit chair", ["You sit in the chair."],
                                 ["Test Player sits in the chair."])
        Tether.createFor(self.player, to=chairThing)
        self.assertCommandOutput("stand up",
                                 ["You can't move, you're tied to a chair."],
                                 ["Test Player struggles."])

    def test_tetheredClothing(self):
        """
        Clothing that is tethered will also prevent movement if you wear it.

        This isn't just simply a test for clothing; it's an example of
        integrating with a foreign system which doesn't know about tethering,
        but can move objects itself.

        Tethering should I{not} have any custom logic related to clothing to
        make this test pass; if it does get custom clothing code for some
        reason, more tests should be added to deal with other systems that do
        not take tethering into account (and vice versa).
        """
        Garment.createFor(self.ball,
                          garmentDescription=u"A lovely ball.",
                          garmentSlots=[u"head"])
        self.assertCommandOutput("wear ball", ["You put on the ball."],
                                 ["Test Player puts on a ball."])
        self.assertCommandOutput(
            "go north", ["You can't move, you're still holding a ball."],
            ["Test Player struggles with a ball."])
Пример #23
0
 def room(name):
     it = Thing(store=store, name=name)
     Container.createFor(it, capacity=1000)
     return it
Пример #24
0
class SitAndStandTests(CommandTestCaseMixin, TestCase):
    """
    Tests for the 'sit' and 'stand' actions.
    """

    def setUp(self):
        """
        Create a room, with a dude in it, and a chair he can sit in.
        """
        CommandTestCaseMixin.setUp(self)
        self.chairThing = Thing(store=self.store, name=u"chair")
        self.chairThing.moveTo(self.location)
        self.chair = Chair.createFor(self.chairThing)


    def test_sitDown(self):
        """
        Sitting in a chair should move your location to that chair.
        """
        self.assertCommandOutput(
            "sit chair",
            ["You sit in the chair."],
            ["Test Player sits in the chair."])
        self.assertEquals(self.player.location, self.chair.thing)


    def test_standWhenStanding(self):
        """
        You can't stand up - you're already standing up.
        """
        self.assertCommandOutput(
            "stand up",
            ["You're already standing."])


    def test_standWhenSitting(self):
        """
        If a player stands up when sitting in a chair, they should be seen to
        stand up, and they should be placed back into the room where the chair
        is located.
        """
        self.test_sitDown()
        self.assertCommandOutput(
            "stand up",
            ["You stand up."],
            ["Test Player stands up."])
        self.assertEquals(self.player.location, self.location)


    def test_takeWhenSitting(self):
        """
        When a player is seated, they should still be able to take objects on
        the floor around them.
        """
        self.test_sitDown()
        self.ball = Thing(store=self.store, name=u'ball')
        self.ball.moveTo(self.location)
        self.assertCommandOutput(
            "take ball",
            ["You take a ball."],
            ["Test Player takes a ball."])


    def test_moveWhenSitting(self):
        """
        A player who is sitting shouldn't be able to move without standing up
        first.
        """
        self.test_sitDown()
        otherRoom = createLocation(self.store, u"elsewhere", None).thing
        Exit.link(self.location, otherRoom, u'north')
        self.assertCommandOutput(
            "go north",
            ["You can't do that while sitting down."])
        self.assertCommandOutput(
            "go south",
            ["You can't go that way."])


    def test_lookWhenSitting(self):
        """
        Looking around when sitting should display the description of the room.
        """
        self.test_sitDown()
        self.assertCommandOutput(
            "look",
            # I'd like to add ', in the chair' to this test, but there's
            # currently no way to modify the name of the object being looked
            # at.
            [E("[ Test Location ]"),
             "Location for testing.",
             "Here, you see Observer Player and a chair."])
Пример #25
0
class GlassBoxTests(CommandTestCaseMixin, TestCase):
    """
    Tests for L{GlassBox}
    """

    def setUp(self):
        """
        Create a room with a L{GlassBox} in it, which itself contains a ball.
        """
        CommandTestCaseMixin.setUp(self)
        self.box = Thing(store=self.store, name=u'box',
                         description=u'The system under test.')
        self.ball = Thing(store=self.store, name=u'ball',
                          description=u'an interesting object')
        self.container = Container.createFor(self.box)
        GlassBox.createFor(self.box)
        self.ball.moveTo(self.box)
        self.box.moveTo(self.location)
        self.container.closed = True


    def test_lookThrough(self):
        """
        You can see items within a glass box by looking at them directly.
        """
        self.assertCommandOutput(
            "look at ball",
            [E("[ ball ]"),
             "an interesting object"])


    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."])


    def test_take(self):
        """
        You can't take items within a glass box.
        """
        self.assertCommandOutput(
            "get ball",
            ["You can't reach through the glass box."])


    def test_openTake(self):
        """
        Taking items from a glass box should work if it's open.
        """
        self.container.closed = False
        self.assertCommandOutput(
            "get ball",
            ["You take a ball."],
            ["Test Player takes a ball."])


    def test_put(self):
        """
        You can't put items into a glass box.
        """
        self.container.closed = False
        self.ball.moveTo(self.location)
        self.container.closed = True
        self.assertCommandOutput(
            "put ball in box",
            ["The box is closed."])


    def test_whyNot(self):
        """
        A regression test; there was a bug where glass boxes would interfere
        with normal target-acquisition error reporting.
        """
        self.assertCommandOutput(
            "get foobar",
            ["Nothing like that around here."])
Пример #26
0
class TetherTest(CommandTestCaseMixin, TestCase):
    """
    A test for tethering an item to its location, such that a player who picks
    it up can't leave until they drop it.
    """

    def setUp(self):
        """
        Tether a ball to the room.
        """
        CommandTestCaseMixin.setUp(self)
        self.ball = Thing(store=self.store, name=u'ball')
        self.ball.moveTo(self.location)
        self.tether = Tether.createFor(self.ball, to=self.location)
        self.otherPlace = Thing(store=self.store, name=u'elsewhere')
        Container.createFor(self.otherPlace, capacity=1000)
        Exit.link(self.location, self.otherPlace, u'north')


    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."])


    def test_allTiedUp(self):
        """
        If you're tied to a chair, you can't leave.
        """
        chairThing = Thing(store=self.store, name=u'chair')
        chairThing.moveTo(self.location)
        chair = Chair.createFor(chairThing)
        self.assertCommandOutput("sit chair",
                                 ["You sit in the chair."],
                                 ["Test Player sits in the chair."])
        Tether.createFor(self.player, to=chairThing)
        self.assertCommandOutput(
            "stand up",
            ["You can't move, you're tied to a chair."],
            ["Test Player struggles."])


    def test_tetheredClothing(self):
        """
        Clothing that is tethered will also prevent movement if you wear it.

        This isn't just simply a test for clothing; it's an example of
        integrating with a foreign system which doesn't know about tethering,
        but can move objects itself.

        Tethering should I{not} have any custom logic related to clothing to
        make this test pass; if it does get custom clothing code for some
        reason, more tests should be added to deal with other systems that do
        not take tethering into account (and vice versa).
        """
        Garment.createFor(self.ball, garmentDescription=u"A lovely ball.",
                          garmentSlots=[u"head"])
        self.assertCommandOutput(
            "wear ball",
            ["You put on the ball."],
            ["Test Player puts on a ball."])
        self.assertCommandOutput(
            "go north",
            ["You can't move, you're still holding a ball."],
            ["Test Player struggles with a ball."])
Пример #27
0
 def setUp(self):
     """
     Create a store with a thing in it.
     """
     self.store = Store()
     self.thing = Thing(store=self.store, name=u'test object')
Пример #28
0
 def setUp(self):
     self.thing = Thing(name=u"alice", gender=Gender.FEMALE)