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)
from durus.connection import Connection from grailmud.rooms import Room from grailmud.objects import MUDObject, NamedObject from grailmud.npcs.chatty import ChattyDelegate from grailmud.ticks import Ticker startroom = Room('An unremarkable moor.', 'This moor is extremely bare. Overly so, perhaps. There ' 'is a definite air of blandness about its grey horizon ' 'and overcast sky. The ground is anonymous and blank; ' 'grey dust litters the floor, and that is about all which ' 'can be said about it. Even the air seems to be steeped in' ' mediocrity - a lukewarm temperature, with no discernable' ' exciting scents.') eliza = NamedObject('a bespectacled old lady', 'Eliza', set(['old', 'lady', 'woman']), startroom) eliza.addDelegate(ChattyDelegate(eliza)) startroom.add(eliza) if os.access("mudlib.durus", os.F_OK): os.remove("mudlib.durus") try: connection = Connection(FileStorage("mudlib.durus")) root = connection.get_root() # pylint: disable-msg= E1101,W0212 #pylint doesn't know about our metaclass hackery, and complains about the #use of the leading underscore variables. root['startroom'] = startroom
def test_caseless_addition_to_name_registry(): obj = NamedObject('', 'FOO', set(), None) assert 'FOO' not in NamedObject._name_registry assert NamedObject._name_registry['foo'] is obj NamedObject._name_registry.clear()
def test_caseless_naming_in_adjs(): obj = NamedObject('', 'FOO', set(), None) assert obj.adjs == set(['foo']) NamedObject._name_registry.clear()
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)]