def setUp(self): self.room = AnonyRoom() self.actor = MUDObject(self.room) self.target = TargettableObject("", set(['rabbit']), self.room) self.onlooker = MUDObject(self.room) self.other_room_target = TargettableObject('', set(), None) self.setup_for_object(self.actor) self.setup_for_object(self.target) self.setup_for_object(self.onlooker) self.info = LineInfo(instigator=self.actor)
def test_at_least_calls_the_base___Xstate__(): obj = MUDObject(None) s = pickle.dumps(obj) try: o = pickle.loads(s) except RuntimeError: #well, we called it... pass else: assert False, "got %r instead" % o
def setUp(self): self.room = AnonyRoom() self.actor = MUDObject(self.room) self.target = TargettableObject("a killer rabbit", set(['bunny', 'killer', 'rabbit']), self.room) self.setup_for_object(self.actor) self.setup_for_object(self.target) self.info = MockInfo(self.actor)
def setUp(self): self.room = AnonyRoom() self.target = TargettableObject('a killer rabbit', set(['killer', 'rabbit']), self.room) self.actor = MUDObject(self.room) self.setup_for_object(self.actor) self.setup_for_object(self.target) self.goodblob, = object_pattern.parseString('killer rabbit') self.badblob, = object_pattern.parseString("bogus bunny") self.info = MockInfo(self.actor)
def setUp(self): self.room = AnonyRoom() self.target = TargettableObject( "a killer rabbit", set(['killer', 'rabbit', 'bunny', 'fluffy']), self.room) self.setup_for_object(self.target) self.actor = MUDObject(self.room) self.setup_for_object(self.actor) targetSet(self.actor, "bob", self.target) self.info = LineInfoMockup(self.actor) self.bogusroom = AnonyRoom()
def test_default_targetting_shorts(): assert MUDObject(None).targetting_shorts == {}
def setUp(self): self.room = AnonyRoom() self.actor = MUDObject(self.room) self.setup_for_object(self.actor)
def test_deafness_turning_off(): obj = MUDObject(None) obj.deaf = True deafOff(obj) assert not obj.deaf
def test_adding(): r = Room('A blank room', 'Nothing to see here, move along.') obj = MUDObject(None) r.add(obj) assert obj in r.contents
def setUp(self): self.obj = MockObjectWithCommands(None) self.setup_for_object(self.obj) self.failobj = MUDObject(None) self.setup_for_object(self.failobj)
class TesterForListening(object): def setUp(self): self.obj = MUDObject(None) self.obj.addDelegate(DelegateHelper(self.obj)) def test_unregister(self): self.obj.removeDelegate(self.obj.delegate) def test_event_passing(self): self.obj.receiveEvent(BaseEvent()) assert self.obj.delegate.received == [BaseEvent()] def test_event_flushing(self): self.obj.eventFlush() assert self.obj.delegate.flushed def test_bad_unregister(self): self.obj.delegates.remove(self.obj.delegate) try: self.obj.removeDelegate(self.obj.delegate) except ValueError: pass else: assert False def test_bad_register(self): try: self.obj.addDelegate(self.obj.delegate) except ValueError: pass else: assert False
def setUp(self): self.obj = MUDObject(None) self.obj.more_limiter = MoreLimiter(10) self.setup_for_object(self.obj)
def test_default_deafness(): assert not MUDObject(None).deaf
def setUp(self): self.obj = MUDObject(None) self.setup_for_object(self.obj)
class TestActionsAndEvents(SetupHelper): def setUp(self): self.obj = MUDObject(None) self.setup_for_object(self.obj) def test_deaf_on_success(self): deafOn(self.obj) assert self.obj.delegate.received == [DeafnessOnEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_on_failure(self): self.obj.deaf = True deafOn(self.obj) assert self.obj.delegate.received == [DeafnessOnAlreadyEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_off_failure(self): deafOff(self.obj) assert self.obj.delegate.received == [DeafnessOffAlreadyEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_off_success(self): self.obj.deaf = True deafOff(self.obj) assert self.obj.delegate.received == [DeafnessOffEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_on_success_with_parsing(self): deafDistributor(self.obj, 'on', None) assert self.obj.delegate.received == [DeafnessOnEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_on_failure_with_parsing(self): self.obj.deaf = True deafDistributor(self.obj, 'on', None) assert self.obj.delegate.received == [DeafnessOnAlreadyEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_off_failure_with_parsing(self): deafDistributor(self.obj, 'off', None) assert self.obj.delegate.received == [DeafnessOffAlreadyEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_off_success_with_parsing(self): self.obj.deaf = True deafDistributor(self.obj, 'off', None) assert self.obj.delegate.received == [DeafnessOffEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_interesting_but_correct_syntaxes(self): for cmd in [" %s", "%s ", "\t%s ", "%s\t", "\t %s", "\r\t%s", "%s\r ", "%s \r ", "%s", "%s \t", "%s foo", "%sbar"]: deafDistributor(self.obj, cmd % 'on', None) deafDistributor(self.obj, cmd % 'off', None) assert self.obj.delegate.received == [DeafnessOnEvent(), DeafnessOffEvent()], \ "Failed on %r, self.delegate.received is %r" % \ (cmd, self.delegate.received) self.obj.delegate.received = [] deafDistributor(self.obj, cmd % 'ON', None) deafDistributor(self.obj, cmd % 'OFF', None) assert self.obj.delegate.received == [DeafnessOnEvent(), DeafnessOffEvent()], \ "Failed on %r, self.delegate.received is %r" % \ (cmd, self.delegate.received) self.obj.delegate.received = [] def test_wrong_syntax(self): for cmd in ['this', 'is', 'all wrong', 'and', 'should', 'not', 'turn', 'it on', 'or off']: deafDistributor(self.obj, cmd, None) assert self.obj.delegate.received == \ [BadSyntaxEvent(syntaxmessage)],\ "Failed on %r, self.delegate.received is %r" % \ (cmd, self.delegate.received) self.obj.delegate.received = [] def test_AudibleEvent_filtering(self): self.obj.deaf = True self.obj.receiveEvent(AudibleEvent()) print self.obj.delegate.received assert self.obj.delegate.received == []
def test_look_at_nowhere(self): lookAt(self.actor, MUDObject(None)) assert self.actor.delegate.received == [UnfoundObjectEvent()]
class TestActionsAndEvents(SetupHelper): def setUp(self): self.obj = MUDObject(None) self.setup_for_object(self.obj) def test_deaf_on_success(self): deafOn(self.obj) assert self.obj.delegate.received == [DeafnessOnEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_on_failure(self): self.obj.deaf = True deafOn(self.obj) assert self.obj.delegate.received == [DeafnessOnAlreadyEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_off_failure(self): deafOff(self.obj) assert self.obj.delegate.received == [DeafnessOffAlreadyEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_off_success(self): self.obj.deaf = True deafOff(self.obj) assert self.obj.delegate.received == [DeafnessOffEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_on_success_with_parsing(self): deafDistributor(self.obj, 'on', None) assert self.obj.delegate.received == [DeafnessOnEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_on_failure_with_parsing(self): self.obj.deaf = True deafDistributor(self.obj, 'on', None) assert self.obj.delegate.received == [DeafnessOnAlreadyEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_off_failure_with_parsing(self): deafDistributor(self.obj, 'off', None) assert self.obj.delegate.received == [DeafnessOffAlreadyEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_deaf_off_success_with_parsing(self): self.obj.deaf = True deafDistributor(self.obj, 'off', None) assert self.obj.delegate.received == [DeafnessOffEvent()], \ "self.delegate.received is %r" % self.delegate.received def test_interesting_but_correct_syntaxes(self): for cmd in [ " %s", "%s ", "\t%s ", "%s\t", "\t %s", "\r\t%s", "%s\r ", "%s \r ", "%s", "%s \t", "%s foo", "%sbar" ]: deafDistributor(self.obj, cmd % 'on', None) deafDistributor(self.obj, cmd % 'off', None) assert self.obj.delegate.received == [DeafnessOnEvent(), DeafnessOffEvent()], \ "Failed on %r, self.delegate.received is %r" % \ (cmd, self.delegate.received) self.obj.delegate.received = [] deafDistributor(self.obj, cmd % 'ON', None) deafDistributor(self.obj, cmd % 'OFF', None) assert self.obj.delegate.received == [DeafnessOnEvent(), DeafnessOffEvent()], \ "Failed on %r, self.delegate.received is %r" % \ (cmd, self.delegate.received) self.obj.delegate.received = [] def test_wrong_syntax(self): for cmd in [ 'this', 'is', 'all wrong', 'and', 'should', 'not', 'turn', 'it on', 'or off' ]: deafDistributor(self.obj, cmd, None) assert self.obj.delegate.received == \ [BadSyntaxEvent(syntaxmessage)],\ "Failed on %r, self.delegate.received is %r" % \ (cmd, self.delegate.received) self.obj.delegate.received = [] def test_AudibleEvent_filtering(self): self.obj.deaf = True self.obj.receiveEvent(AudibleEvent()) print self.obj.delegate.received assert self.obj.delegate.received == []
def test_speakTo_fails_with_nonTargettableObject(self): speakTo(self.actor, MUDObject(None), "foo") assert self.actor.delegate.received == [UnfoundObjectEvent()]
def test_register(): obj = MUDObject(None) obj.addDelegate(DelegateHelper(obj))
def test_equality(): m = MUDObject(None) assert m == m assert MUDObject(None) != m
def setUp(self): self.obj = MUDObject(None) self.obj.addDelegate(DelegateHelper(self.obj))
def test_hashability(): s = set([MUDObject(None), MUDObject(None)]) assert len(s) == 2
def test_deafness_turning_on(): obj = MUDObject(None) deafOn(obj) assert obj.deaf