def setUp(self): self.room = Room("Just outside a dark cave.", "") self.actor = TargettableObject("a decapitated knight", set(['shiny', 'dead']), self.room) self.roomtarget = TargettableObject("a killer rabbit", set(['bunny', 'fluffy', "rabbit", 'murderous', "killer"]), self.room) self.invtarget = NamedObject("a surprised-looking decapitated head", "Boris", set(["head", "dead"]), self.actor.inventory) self.otherroom = Room("Just inside a dark cave.", "") self.exit = TargettableExitObject(self.room, self.otherroom, "the mouth of a cave", set(["cave", "mouth"])) self.room.add(self.actor) self.room.add(self.roomtarget) self.room.add(self.invtarget) self.room.add(self.exit) self.setup_for_object(self.actor) self.info = MockInfo(self.actor)
def test_TargettableExitObject_matching(): obj = TargettableExitObject(None, None, '', set(['foo'])) assert obj.match(set(['foo']))
class TestEventSending(SetupHelper): def setUp(self): self.room = Room("Just outside a dark cave.", "") self.actor = TargettableObject("a decapitated knight", set(['shiny', 'dead']), self.room) self.roomtarget = TargettableObject("a killer rabbit", set(['bunny', 'fluffy', "rabbit", 'murderous', "killer"]), self.room) self.invtarget = NamedObject("a surprised-looking decapitated head", "Boris", set(["head", "dead"]), self.actor.inventory) self.otherroom = Room("Just inside a dark cave.", "") self.exit = TargettableExitObject(self.room, self.otherroom, "the mouth of a cave", set(["cave", "mouth"])) self.room.add(self.actor) self.room.add(self.roomtarget) self.room.add(self.invtarget) self.room.add(self.exit) self.setup_for_object(self.actor) self.info = MockInfo(self.actor) def tearDown(self): self.room.remove_from_instances() self.actor.remove_from_instances() self.roomtarget.remove_from_instances() self.invtarget.remove_from_instances() NamedObject._name_registry.clear() self.exit.remove_from_instances() def test_look_at_room_TargettableObject(self): lookAt(self.actor, self.roomtarget) assert self.actor.delegate.received == [LookAtEvent(self.roomtarget)] def test_look_at_inventory_TargettableObject(self): lookAt(self.actor, self.invtarget) assert self.actor.delegate.received == [LookAtEvent(self.invtarget)] def test_look_at_nowhere(self): lookAt(self.actor, MUDObject(None)) assert self.actor.delegate.received == [UnfoundObjectEvent()] def test_look_at_room(self): lookRoom(self.actor) assert self.actor.delegate.received == [LookRoomEvent(self.room)] def test_look_at_exit(self): lookAt(self.actor, self.exit) assert self.actor.delegate.received == [LookRoomEvent(self.otherroom)] def test_look_at_parsing_no_at(self): lookDistributor(self.actor, 'boris', self.info) print self.actor.delegate.received assert self.actor.delegate.received == [LookAtEvent(self.invtarget)] def test_look_at_parsing(self): lookDistributor(self.actor, "at killer rabbit", self.info) print self.actor.delegate.received assert self.actor.delegate.received == [LookAtEvent(self.roomtarget)] def test_look_at_parsing_failure(self): lookDistributor(self.actor, "at foobar", self.info) assert self.actor.delegate.received == [UnfoundObjectEvent()] def test_look_parsing(self): lookDistributor(self.actor, "", self.info) print self.actor.delegate.received assert self.actor.delegate.received == [LookRoomEvent(self.room)]