Beispiel #1
0
    def setUp(self):
        """
        Set up a store with a location, a player and an observer.
        """
        self.store = store.Store()
        locContainer = createLocation(
            self.store, u"Test Location", u"Location for testing.")
        self.location = locContainer.thing
        self.world = ImaginaryWorld(store=self.store, origin=self.location)
        self.player = self.world.create(
            u"Test Player", gender=self.genderForTest)
        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()
Beispiel #2
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()
Beispiel #3
0
 def setUp(self):
     self.store = store.Store()
     self.world = ImaginaryWorld(store=self.store)
     self.daisy = self.world.create(u"daisy", gender=language.Gender.FEMALE)
     self.observer = self.world.create(u"NONDESCRIPT",
                                       gender=language.Gender.MALE)
     self.dukes = garments.createPants(store=self.store,
                                       name=u'pair of Daisy Dukes')
     self.blouse = garments.createShirt(store=self.store,
                                        name=u"blue blouse")
     self.undies = garments.createUnderwear(store=self.store,
                                            name=u"pair of lacy underwear")
Beispiel #4
0
 def setUp(self):
     self.store = store.Store()
     self.world = ImaginaryWorld(store=self.store)
     self.mannequin = self.world.create(u"mannequin",
                                        gender=language.Gender.NEUTER,
                                        proper=False)
     self.observer = self.world.create(u"NONDESCRIPT")
     self.underwear = garments.createPants(store=self.store,
                                           name=u'pair of blue pants')
     self.blouse = garments.createShirt(store=self.store,
                                        name=u"blue blouse")
     self.undies = garments.createUnderwear(
         store=self.store, name=u"pair of polka dot underwear")
Beispiel #5
0
    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())
Beispiel #6
0
def makeTextServer(reactor, world=None):
    store = Store()
    if world is not None:
        world = loadWorld(world, store)
        actorThing = findActorThing(store)
    else:
        world = ImaginaryWorld(store=store)
        actorThing = world.create("player")

    tsb = ConsoleTextServer(Player(actorThing), sys.__stdin__.fileno())
    def winchAccess(signum, frame):
        reactor.callFromThread(tsb.terminalSize, *getTerminalSize()[::-1])
    signal.signal(signal.SIGWINCH, winchAccess)
    return tsb
Beispiel #7
0
 def test_create(self):
     """
     L{ImaginaryWorld.create} returns a L{Thing} which is adaptable to
     L{IActor}, L{IContainer}, and L{IClothingWearer} and which is contained
     by the world's C{origin} L{Thing}.
     """
     name = u"foo"
     store = Store()
     world = ImaginaryWorld(store=store)
     character = world.create(name)
     self.assertEqual(character.name, name)
     self.assertTrue(IContainer(world.origin).contains(character))
     self.assertNotIdentical(IActor(character, None), None)
     self.assertNotIdentical(IContainer(character, None), None)
     self.assertNotIdentical(IClothingWearer(character, None), None)
Beispiel #8
0
 def test_create(self):
     """
     L{ImaginaryWorld.create} returns a L{Thing} which is adaptable to
     L{IActor}, L{IContainer}, and L{IClothingWearer} and which is contained
     by the world's C{origin} L{Thing}.
     """
     name = u"foo"
     store = Store()
     world = ImaginaryWorld(store=store)
     character = world.create(name)
     self.assertEqual(character.name, name)
     self.assertTrue(IContainer(world.origin).contains(character))
     self.assertNotIdentical(IActor(character, None), None)
     self.assertNotIdentical(IContainer(character, None), None)
     self.assertNotIdentical(IClothingWearer(character, None), None)
Beispiel #9
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()
Beispiel #10
0
def makeTextServer(reactor, world=None):
    store = Store()
    if world is not None:
        world = loadWorld(world, store)
        actorThing = findActorThing(store)
    else:
        world = ImaginaryWorld(store=store)
        actorThing = world.create("player")

    tsb = ConsoleTextServer(Player(actorThing), sys.__stdin__.fileno())

    def winchAccess(signum, frame):
        reactor.callFromThread(tsb.terminalSize, *getTerminalSize()[::-1])

    signal.signal(signal.SIGWINCH, winchAccess)
    return tsb
Beispiel #11
0
 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)
Beispiel #12
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())
Beispiel #13
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
Beispiel #14
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
Beispiel #15
0
    def test_creationEvent(self):
        """
        When a new L{Thing} is created via L{ImaginaryWorld.create}, its
        addition to L{ImaginaryWorld.origin} is broadcast to that location.
        """
        store = Store()
        world = ImaginaryWorld(store=store)
        observer = world.create(u"observer")

        # There really needs to be a way to get into the event dispatch
        # system.  It's so hard right now that I'm not even going to try,
        # instead I'll look at some strings that get written to a transport.
        observingPlayer = Player(observer)
        transport = StringTransport()
        observingPlayer.setProtocol(PlayerProtocol(transport))

        # Make another thing for the observer to watch the creation of.
        world.create(u"foo")

        self.assertEquals(transport.value(), "Foo arrives.\n")
Beispiel #16
0
 def setUp(self):
     self.store = store.Store()
     self.world = ImaginaryWorld(store=self.store)
     self.daisy = self.world.create(u"daisy", gender=language.Gender.FEMALE)
     self.observer = self.world.create(u"NONDESCRIPT", gender=language.Gender.MALE)
     self.dukes = garments.createPants(store=self.store,
                                       name=u'pair of Daisy Dukes')
     self.blouse = garments.createShirt(store=self.store,
                                        name=u"blue blouse")
     self.undies = garments.createUnderwear(store=self.store,
                                            name=u"pair of lacy underwear")
Beispiel #17
0
    def test_creationEvent(self):
        """
        When a new L{Thing} is created via L{ImaginaryWorld.create}, its
        addition to L{ImaginaryWorld.origin} is broadcast to that location.
        """
        store = Store()
        world = ImaginaryWorld(store=store)
        observer = world.create(u"observer")

        # There really needs to be a way to get into the event dispatch
        # system.  It's so hard right now that I'm not even going to try,
        # instead I'll look at some strings that get written to a transport.
        observingPlayer = Player(observer)
        transport = StringTransport()
        observingPlayer.setProtocol(PlayerProtocol(transport))

        # Make another thing for the observer to watch the creation of.
        world.create(u"foo")

        self.assertEquals(transport.value(), "Foo arrives.\n")
Beispiel #18
0
    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())
Beispiel #19
0
 def setUp(self):
     self.store = store.Store()
     self.world = ImaginaryWorld(store=self.store)
     self.mannequin = self.world.create(u"mannequin",
                                        gender=language.Gender.NEUTER,
                                        proper=False)
     self.observer = self.world.create(u"NONDESCRIPT")
     self.underwear = garments.createPants(store=self.store,
                                           name=u'pair of blue pants')
     self.blouse = garments.createShirt(store=self.store,
                                        name=u"blue blouse")
     self.undies = garments.createUnderwear(
         store=self.store, name=u"pair of polka dot underwear"
     )
Beispiel #20
0
 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)
Beispiel #21
0
class LookTestCase(unittest.TestCase):
    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())


    def testLookAroundEventBroadcasting(self):
        action.LookAround().runEventTransaction(
            self.player, u"look", {})
        evts = self.actor.getIntelligence().observedConcepts
        self.assertEquals(len(evts), 1)
        self.failUnless(isinstance(evts[0], events.Success))


    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")
Beispiel #22
0
class WhoTestCase(unittest.TestCase):
    """
    Tests for L{ExpressWho} and the I{who} command.
    """
    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)


    def testWhoExpression(self):
        expr = action.ExpressWho(self.world)
        crud = ''.join(list(expr.plaintext(self.player)))
        self.assertEquals(len(crud.splitlines()), 3, crud)


    def testOthersAsWell(self):
        for other in self.others:
            self.world.loggedIn(other)
        expr = action.ExpressWho(self.world)
        crud = ''.join(list(expr.plaintext(self.player)))
        self.assertEquals(len(crud.splitlines()), 8, crud)
        for player in self.others:
            self.failUnless(player.name in crud)


    def testEventReceived(self):
        action.Who().do(self.actor, "who")
        self.assertEquals(len(self.intelligence.events), 1)
        self.failUnless(isinstance(self.intelligence.events[0], action.ExpressWho))
        self.assertIdentical(self.intelligence.events[0].original, self.world)
Beispiel #23
0
class WhoTestCase(unittest.TestCase):
    """
    Tests for L{ExpressWho} and the I{who} command.
    """
    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)

    def testWhoExpression(self):
        expr = action.ExpressWho(self.world)
        crud = ''.join(list(expr.plaintext(self.player)))
        self.assertEquals(len(crud.splitlines()), 3, crud)

    def testOthersAsWell(self):
        for other in self.others:
            self.world.loggedIn(other)
        expr = action.ExpressWho(self.world)
        crud = ''.join(list(expr.plaintext(self.player)))
        self.assertEquals(len(crud.splitlines()), 8, crud)
        for player in self.others:
            self.failUnless(player.name in crud)

    def testEventReceived(self):
        action.Who().do(self.actor, "who")
        self.assertEquals(len(self.intelligence.events), 1)
        self.failUnless(
            isinstance(self.intelligence.events[0], action.ExpressWho))
        self.assertIdentical(self.intelligence.events[0].original, self.world)
Beispiel #24
0
class GarmentPluginTestCase(commandutils.LanguageMixin, unittest.TestCase):
    def setUp(self):
        self.store = store.Store()
        self.world = ImaginaryWorld(store=self.store)
        self.mannequin = self.world.create(u"mannequin",
                                           gender=language.Gender.NEUTER,
                                           proper=False)
        self.observer = self.world.create(u"NONDESCRIPT")
        self.underwear = garments.createPants(store=self.store,
                                              name=u'pair of blue pants')
        self.blouse = garments.createShirt(store=self.store,
                                           name=u"blue blouse")
        self.undies = garments.createUnderwear(
            store=self.store, name=u"pair of polka dot underwear")

    def visualizeMannequin(self):
        """
        Present the description rendered when our protagonist, the mannequin,
        looks at itself.

        @return: a concept representing Mannequin's self-description, including
            all its clothes.
        @rtype: L{IConcept}
        """
        [description] = vision.visualizations(
            self.mannequin,
            lambda path: path.targetAs(iimaginary.IThing) is self.mannequin)
        return description

    def _creationTest(self, garment):
        self.failUnless(
            iimaginary.IClothing.providedBy(iimaginary.IClothing(garment)))

    def testShirtCreation(self):
        self._creationTest(
            garments.createShirt(store=self.store, name=u'red shirt'))

    def testPantsCreation(self):
        self._creationTest(
            garments.createPants(store=self.store, name=u'blue pants'))

    def testPersonIsAWearer(self):
        self.failUnless(
            iimaginary.IClothingWearer.providedBy(
                iimaginary.IClothingWearer(self.mannequin)))

    def testPersonWearsPants(self):
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.underwear))

        description = self.visualizeMannequin()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u'[ mannequin ]\n'
            u'the mannequin is great.\n'
            u'It is wearing a pair of blue pants.')

    def testPersonRemovesPants(self):
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.underwear))
        iimaginary.IClothingWearer(self.mannequin).takeOff(
            iimaginary.IClothing(self.underwear))
        description = self.visualizeMannequin()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u'[ mannequin ]\n'
            u'the mannequin is great.\n'
            u'It is naked.\n'
            u'It is carrying a pair of blue pants.')
        self.assertIdentical(self.underwear.location, self.mannequin)

    def testPersonRemovesPantsAndUnderwear(self):
        wearer = iimaginary.IClothingWearer(self.mannequin)
        wearer.putOn(iimaginary.IClothing(self.undies))
        wearer.putOn(iimaginary.IClothing(self.underwear))
        wearer.takeOff(iimaginary.IClothing(self.underwear))
        wearer.takeOff(iimaginary.IClothing(self.undies))
        description = self.visualizeMannequin()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u'[ mannequin ]\n'
            u'the mannequin is great.\n'
            u'It is naked.\n'
            u'It is carrying a pair of blue pants and a pair of polka dot '
            u'underwear.')
        self.assertIdentical(self.underwear.location, self.mannequin)

    def test_cantDropSomethingYouAreWearing(self):
        """
        If you're wearing an article of clothing, you should not be able to
        drop it until you first take it off.  After taking it off, however, you
        can move it around just fine.
        """
        wearer = iimaginary.IClothingWearer(self.mannequin)
        wearer.putOn(iimaginary.IClothing(self.undies))
        af = self.assertRaises(ActionFailure, self.undies.moveTo,
                               self.mannequin.location)
        self.assertEquals(
            u''.join(af.event.plaintext(self.mannequin)),
            u"You can't move the pair of polka dot underwear "
            u"without removing it first.\n")

        wearer.takeOff(iimaginary.IClothing(self.undies))
        self.undies.moveTo(self.mannequin.location)
        self.assertEquals(self.mannequin.location, self.undies.location)

    def testTakeOffUnderwearBeforePants(self):
        # TODO - underwear removal skill
        wearer = iimaginary.IClothingWearer(self.mannequin)
        wearer.putOn(iimaginary.IClothing(self.undies))
        wearer.putOn(iimaginary.IClothing(self.underwear))

        self.assertRaises(garments.InaccessibleGarment, wearer.takeOff,
                          iimaginary.IClothing(self.undies))

    def testPersonWearsPantsAndShirt(self):
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.underwear))
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.blouse))

        description = self.visualizeMannequin()

        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u"[ mannequin ]\n"
            u"the mannequin is great.\n"
            u"It is wearing a blue blouse and a pair of blue pants.")

    def testPersonWearsUnderpantsAndPants(self):
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.undies))
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.underwear))

        description = self.visualizeMannequin()

        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u"[ mannequin ]\n"
            u"the mannequin is great.\n"
            u"It is wearing a pair of blue pants.")

    def testPersonWearsPantsAndFailsAtPuttingOnUnderpants(self):
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.underwear))
        self.assertRaises(garments.TooBulky,
                          iimaginary.IClothingWearer(self.mannequin).putOn,
                          iimaginary.IClothing(self.undies))
Beispiel #25
0
class GarmentPluginTestCase(commandutils.LanguageMixin, unittest.TestCase):
    def setUp(self):
        self.store = store.Store()
        self.world = ImaginaryWorld(store=self.store)
        self.daisy = self.world.create(u"daisy", gender=language.Gender.FEMALE)
        self.observer = self.world.create(u"NONDESCRIPT", gender=language.Gender.MALE)
        self.dukes = garments.createPants(store=self.store,
                                          name=u'pair of Daisy Dukes')
        self.blouse = garments.createShirt(store=self.store,
                                           name=u"blue blouse")
        self.undies = garments.createUnderwear(store=self.store,
                                               name=u"pair of lacy underwear")


    def _creationTest(self, garment):
        self.failUnless(
            iimaginary.IClothing.providedBy(iimaginary.IClothing(garment)))


    def testShirtCreation(self):
        self._creationTest(
            garments.createShirt(store=self.store, name=u'red shirt'))


    def testPantsCreation(self):
        self._creationTest(
            garments.createPants(store=self.store, name=u'blue pants'))


    def testPersonIsAWearer(self):
        self.failUnless(iimaginary.IClothingWearer.providedBy(
            iimaginary.IClothingWearer(self.daisy)))


    def testPersonWearsPants(self):
        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))

        description = self.daisy.visualize()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u'[ daisy ]\n'
            u'daisy is great.\n'
            u'She is wearing a pair of Daisy Dukes.')


    def testPersonRemovesPants(self):
        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))
        iimaginary.IClothingWearer(self.daisy).takeOff(
            iimaginary.IClothing(self.dukes))
        description = self.daisy.visualize()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u'[ daisy ]\n'
            u'daisy is great.\n'
            u'She is naked.\n'
            u'She is carrying a pair of Daisy Dukes.'
            )
        self.assertIdentical(self.dukes.location, self.daisy)


    def testPersonRemovesPantsAndUnderwear(self):
        wearer = iimaginary.IClothingWearer(self.daisy)
        wearer.putOn(iimaginary.IClothing(self.undies))
        wearer.putOn(iimaginary.IClothing(self.dukes))
        wearer.takeOff(iimaginary.IClothing(self.dukes))
        wearer.takeOff(iimaginary.IClothing(self.undies))
        description = self.daisy.visualize()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u'[ daisy ]\n'
            u'daisy is great.\n'
            u'She is naked.\n'
            u'She is carrying a pair of Daisy Dukes and a pair of lacy '
            u'underwear.'
            )
        self.assertIdentical(self.dukes.location, self.daisy)


    def test_cantDropSomethingYouAreWearing(self):
        """
        If you're wearing an article of clothing, you should not be able to
        drop it until you first take it off.  After taking it off, however, you
        can move it around just fine.
        """
        wearer = iimaginary.IClothingWearer(self.daisy)
        wearer.putOn(iimaginary.IClothing(self.undies))
        af = self.assertRaises(ActionFailure, self.undies.moveTo,
                               self.daisy.location)
        self.assertEquals(
            u''.join(af.event.plaintext(self.daisy)),
            u"You can't move the pair of lacy underwear "
            u"without removing it first.\n")

        wearer.takeOff(iimaginary.IClothing(self.undies))
        self.undies.moveTo(self.daisy.location)
        self.assertEquals(self.daisy.location, self.undies.location)


    def testTakeOffUnderwearBeforePants(self):
        # TODO - underwear removal skill
        wearer = iimaginary.IClothingWearer(self.daisy)
        wearer.putOn(iimaginary.IClothing(self.undies))
        wearer.putOn(iimaginary.IClothing(self.dukes))

        self.assertRaises(garments.InaccessibleGarment,
                          wearer.takeOff, iimaginary.IClothing(self.undies))


    def testPersonWearsPantsAndShirt(self):
        description = self.daisy.visualize()

        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))
        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.blouse))

        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u"[ daisy ]\n"
            u"daisy is great.\n"
            u"She is wearing a blue blouse and a pair of Daisy Dukes.")


    def testPersonWearsUnderpantsAndPants(self):
        description = self.daisy.visualize()

        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.undies))
        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))

        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u"[ daisy ]\n"
            u"daisy is great.\n"
            u"She is wearing a pair of Daisy Dukes.")


    def testPersonWearsPantsAndFailsAtPuttingOnUnderpants(self):
        description = self.daisy.visualize()

        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))
        self.assertRaises(garments.TooBulky,
                          iimaginary.IClothingWearer(self.daisy).putOn,
                          iimaginary.IClothing(self.undies))

    def testWornClothingIsFindable(self):
        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))
        dukes = list(self.daisy.findProviders(
            iimaginary.IClothing, 0))
        self.assertEquals(len(dukes), 1)
        self.assertIdentical(dukes[0].thing, self.dukes)
Beispiel #26
0
class GarmentPluginTestCase(commandutils.LanguageMixin, unittest.TestCase):
    def setUp(self):
        self.store = store.Store()
        self.world = ImaginaryWorld(store=self.store)
        self.daisy = self.world.create(u"daisy", gender=language.Gender.FEMALE)
        self.observer = self.world.create(u"NONDESCRIPT",
                                          gender=language.Gender.MALE)
        self.dukes = garments.createPants(store=self.store,
                                          name=u'pair of Daisy Dukes')
        self.blouse = garments.createShirt(store=self.store,
                                           name=u"blue blouse")
        self.undies = garments.createUnderwear(store=self.store,
                                               name=u"pair of lacy underwear")

    def _creationTest(self, garment):
        self.failUnless(
            iimaginary.IClothing.providedBy(iimaginary.IClothing(garment)))

    def testShirtCreation(self):
        self._creationTest(
            garments.createShirt(store=self.store, name=u'red shirt'))

    def testPantsCreation(self):
        self._creationTest(
            garments.createPants(store=self.store, name=u'blue pants'))

    def testPersonIsAWearer(self):
        self.failUnless(
            iimaginary.IClothingWearer.providedBy(
                iimaginary.IClothingWearer(self.daisy)))

    def testPersonWearsPants(self):
        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))

        description = self.daisy.visualize()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)), u'[ daisy ]\n'
            u'daisy is great.\n'
            u'She is wearing a pair of Daisy Dukes.')

    def testPersonRemovesPants(self):
        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))
        iimaginary.IClothingWearer(self.daisy).takeOff(
            iimaginary.IClothing(self.dukes))
        description = self.daisy.visualize()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)), u'[ daisy ]\n'
            u'daisy is great.\n'
            u'She is naked.\n'
            u'a pair of Daisy Dukes')
        self.assertIdentical(self.dukes.location, self.daisy)

    def testPersonRemovesPantsAndUnderwear(self):
        wearer = iimaginary.IClothingWearer(self.daisy)
        wearer.putOn(iimaginary.IClothing(self.undies))
        wearer.putOn(iimaginary.IClothing(self.dukes))
        wearer.takeOff(iimaginary.IClothing(self.dukes))
        wearer.takeOff(iimaginary.IClothing(self.undies))
        description = self.daisy.visualize()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)), u'[ daisy ]\n'
            u'daisy is great.\n'
            u'She is naked.\n'
            u'a pair of Daisy Dukes and a pair of lacy underwear')
        self.assertIdentical(self.dukes.location, self.daisy)

    def testTakeOffUnderwearBeforePants(self):
        # TODO - underwear removal skill
        wearer = iimaginary.IClothingWearer(self.daisy)
        wearer.putOn(iimaginary.IClothing(self.undies))
        wearer.putOn(iimaginary.IClothing(self.dukes))

        self.assertRaises(garments.InaccessibleGarment, wearer.takeOff,
                          iimaginary.IClothing(self.undies))

    def testPersonWearsPantsAndShirt(self):
        description = self.daisy.visualize()

        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))
        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.blouse))

        self.assertEquals(
            self.flatten(description.plaintext(self.observer)), u"[ daisy ]\n"
            u"daisy is great.\n"
            u"She is wearing a blue blouse and a pair of Daisy Dukes.")

    def testPersonWearsUnderpantsAndPants(self):
        description = self.daisy.visualize()

        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.undies))
        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))

        self.assertEquals(
            self.flatten(description.plaintext(self.observer)), u"[ daisy ]\n"
            u"daisy is great.\n"
            u"She is wearing a pair of Daisy Dukes.")

    def testPersonWearsPantsAndFailsAtPuttingOnUnderpants(self):
        description = self.daisy.visualize()

        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))
        self.assertRaises(garments.TooBulky,
                          iimaginary.IClothingWearer(self.daisy).putOn,
                          iimaginary.IClothing(self.undies))

    def testWornClothingIsFindable(self):
        iimaginary.IClothingWearer(self.daisy).putOn(
            iimaginary.IClothing(self.dukes))
        dukes = list(self.daisy.findProviders(iimaginary.IClothing, 0))
        self.assertEquals(len(dukes), 1)
        self.assertIdentical(dukes[0].thing, self.dukes)
Beispiel #27
0
class CommandTestCaseMixin:
    """
    A mixin for TestCase classes which provides support for testing Imaginary
    environments via command-line transcripts.

    @ivar store: the L{store.Store} containing all the relevant game objects.

    @ivar location: The location where the test is taking place.

    @ivar world: The L{ImaginaryWorld} that created the player.

    @ivar player: The L{Thing} representing the main player.

    @ivar observer: The L{Thing} representing the observer who sees the main
        player's actions.
    """

    genderForTest = language.Gender.FEMALE

    def setUp(self):
        """
        Set up a store with a location, a player and an observer.
        """
        self.store = store.Store()
        locContainer = createLocation(
            self.store, u"Test Location", u"Location for testing.")
        self.location = locContainer.thing
        self.world = ImaginaryWorld(store=self.store, origin=self.location)
        self.player = self.world.create(
            u"Test Player", gender=self.genderForTest)
        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()


    def tearDown(self):
        """
        Disconnect the player and observer from their respective transports.
        """
        for p in self.player, self.observer:
            try:
                p.destroy()
            except AttributeError:
                pass


    def watchCommand(self, command):
        """
        Make C{self.player} run the given command and return the output both
        she and C{self.observer} receive.

        @param command: The textual command to run.
        @type command: C{unicode}
        @return: The player's output and the third-party observer's output.
        @rtype: Two-tuple of C{unicode}
        """
        self.playerWrapper.parse(command)
        return (
            self.transport.value().decode('utf-8'),
            self.otransport.value().decode('utf-8'))


    def assertCommandOutput(self, command, output, observed=()):
        """
        Verify that when C{command} is executed by this
        L{CommandTestCaseMixin.playerWrapper}, C{output} is produced (to the
        actor) and C{observed} is produced (to the observer).

        @param command: The string for L{CommandTestCaseMixin.playerWrapper} to
            execute.
        @type command: L{str}

        @param output: The expected output of C{command} for
            L{CommandTestCaseMixin.player} to observe.
        @type output: iterable of L{str}

        @param observed: The expected output that
            L{CommandTestCaseMixin.observer} will observe.
        @type observed: iterable of L{str}
        """
        if command is not None:
            # Deprecate this or something
            if not isinstance(command, unicode):
                command = unicode(command, 'ascii')
            self.playerWrapper.parse(command)
            output.insert(0, "> " + command)

        results = []
        for perspective, xport, oput in ([
                ('actor' ,self.transport, output),
                ('observer', self.otransport, observed)]):
            results.append([])
            gotLines = xport.value().decode('utf-8').splitlines()
            for i, (got, expected) in enumerate(map(None, gotLines, oput)):
                got = got or ''
                expected = expected or '$^'
                m = compile(expected.rstrip() + '$').match(got.rstrip())
                if m is None:
                    s1 = pprint.pformat(gotLines)
                    s2 = pprint.pformat(oput)
                    raise unittest.FailTest(
                        "\n%s %s\ndid not match expected\n%s\n(Line %d)" % (
                            repr(perspective), s1, s2, i))
                results[-1].append(m)
            xport.clear()
        return results

    # Old alias.
    _test = assertCommandOutput


    def find(self, name):
        return [
            th
            for th in self.player.findProviders(iimaginary.IThing, 1)
            if th.name == name][0]
Beispiel #28
0
class GarmentPluginTestCase(commandutils.LanguageMixin, unittest.TestCase):
    def setUp(self):
        self.store = store.Store()
        self.world = ImaginaryWorld(store=self.store)
        self.mannequin = self.world.create(u"mannequin",
                                           gender=language.Gender.NEUTER,
                                           proper=False)
        self.observer = self.world.create(u"NONDESCRIPT")
        self.underwear = garments.createPants(store=self.store,
                                              name=u'pair of blue pants')
        self.blouse = garments.createShirt(store=self.store,
                                           name=u"blue blouse")
        self.undies = garments.createUnderwear(
            store=self.store, name=u"pair of polka dot underwear"
        )


    def visualizeMannequin(self):
        """
        Present the description rendered when our protagonist, the mannequin,
        looks at itself.

        @return: a concept representing Mannequin's self-description, including
            all its clothes.
        @rtype: L{IConcept}
        """
        [description] = vision.visualizations(
            self.mannequin,
            lambda path: path.targetAs(iimaginary.IThing) is self.mannequin)
        return description


    def _creationTest(self, garment):
        self.failUnless(
            iimaginary.IClothing.providedBy(iimaginary.IClothing(garment)))


    def testShirtCreation(self):
        self._creationTest(
            garments.createShirt(store=self.store, name=u'red shirt'))


    def testPantsCreation(self):
        self._creationTest(
            garments.createPants(store=self.store, name=u'blue pants'))


    def testPersonIsAWearer(self):
        self.failUnless(iimaginary.IClothingWearer.providedBy(
            iimaginary.IClothingWearer(self.mannequin)))


    def testPersonWearsPants(self):
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.underwear))

        description = self.visualizeMannequin()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u'[ mannequin ]\n'
            u'the mannequin is great.\n'
            u'It is wearing a pair of blue pants.')


    def testPersonRemovesPants(self):
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.underwear))
        iimaginary.IClothingWearer(self.mannequin).takeOff(
            iimaginary.IClothing(self.underwear))
        description = self.visualizeMannequin()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u'[ mannequin ]\n'
            u'the mannequin is great.\n'
            u'It is naked.\n'
            u'It is carrying a pair of blue pants.'
            )
        self.assertIdentical(self.underwear.location, self.mannequin)


    def testPersonRemovesPantsAndUnderwear(self):
        wearer = iimaginary.IClothingWearer(self.mannequin)
        wearer.putOn(iimaginary.IClothing(self.undies))
        wearer.putOn(iimaginary.IClothing(self.underwear))
        wearer.takeOff(iimaginary.IClothing(self.underwear))
        wearer.takeOff(iimaginary.IClothing(self.undies))
        description = self.visualizeMannequin()
        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u'[ mannequin ]\n'
            u'the mannequin is great.\n'
            u'It is naked.\n'
            u'It is carrying a pair of blue pants and a pair of polka dot '
            u'underwear.'
            )
        self.assertIdentical(self.underwear.location, self.mannequin)


    def test_cantDropSomethingYouAreWearing(self):
        """
        If you're wearing an article of clothing, you should not be able to
        drop it until you first take it off.  After taking it off, however, you
        can move it around just fine.
        """
        wearer = iimaginary.IClothingWearer(self.mannequin)
        wearer.putOn(iimaginary.IClothing(self.undies))
        af = self.assertRaises(ActionFailure, self.undies.moveTo,
                               self.mannequin.location)
        self.assertEquals(
            u''.join(af.event.plaintext(self.mannequin)),
            u"You can't move the pair of polka dot underwear "
            u"without removing it first.\n")

        wearer.takeOff(iimaginary.IClothing(self.undies))
        self.undies.moveTo(self.mannequin.location)
        self.assertEquals(self.mannequin.location, self.undies.location)


    def testTakeOffUnderwearBeforePants(self):
        # TODO - underwear removal skill
        wearer = iimaginary.IClothingWearer(self.mannequin)
        wearer.putOn(iimaginary.IClothing(self.undies))
        wearer.putOn(iimaginary.IClothing(self.underwear))

        self.assertRaises(garments.InaccessibleGarment,
                          wearer.takeOff, iimaginary.IClothing(self.undies))


    def testPersonWearsPantsAndShirt(self):
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.underwear))
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.blouse))

        description = self.visualizeMannequin()

        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u"[ mannequin ]\n"
            u"the mannequin is great.\n"
            u"It is wearing a blue blouse and a pair of blue pants.")


    def testPersonWearsUnderpantsAndPants(self):
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.undies))
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.underwear))

        description = self.visualizeMannequin()

        self.assertEquals(
            self.flatten(description.plaintext(self.observer)),
            u"[ mannequin ]\n"
            u"the mannequin is great.\n"
            u"It is wearing a pair of blue pants.")


    def testPersonWearsPantsAndFailsAtPuttingOnUnderpants(self):
        iimaginary.IClothingWearer(self.mannequin).putOn(
            iimaginary.IClothing(self.underwear))
        self.assertRaises(garments.TooBulky,
                          iimaginary.IClothingWearer(self.mannequin).putOn,
                          iimaginary.IClothing(self.undies))