Esempio n. 1
0
 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)
Esempio n. 2
0
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
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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()
Esempio n. 6
0
def test_default_targetting_shorts():
    assert MUDObject(None).targetting_shorts == {}
Esempio n. 7
0
 def setUp(self):
     self.room = AnonyRoom()
     self.actor = MUDObject(self.room)
     self.setup_for_object(self.actor)
Esempio n. 8
0
def test_deafness_turning_off():
    obj = MUDObject(None)
    obj.deaf = True
    deafOff(obj)
    assert not obj.deaf
Esempio n. 9
0
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
Esempio n. 10
0
 def setUp(self):
     self.obj = MockObjectWithCommands(None)
     self.setup_for_object(self.obj)
     self.failobj = MUDObject(None)
     self.setup_for_object(self.failobj)
Esempio n. 11
0
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
Esempio n. 12
0
 def setUp(self):
     self.obj = MUDObject(None)
     self.obj.more_limiter = MoreLimiter(10)
     self.setup_for_object(self.obj)
Esempio n. 13
0
def test_default_deafness():
    assert not MUDObject(None).deaf
Esempio n. 14
0
 def setUp(self):
     self.obj = MUDObject(None)
     self.setup_for_object(self.obj)
Esempio n. 15
0
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 == []
Esempio n. 16
0
def test_deafness_turning_off():
    obj = MUDObject(None)
    obj.deaf = True
    deafOff(obj)
    assert not obj.deaf
Esempio n. 17
0
    def test_look_at_nowhere(self):
        lookAt(self.actor, MUDObject(None))

        assert self.actor.delegate.received == [UnfoundObjectEvent()]
Esempio n. 18
0
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 == []
Esempio n. 19
0
 def test_speakTo_fails_with_nonTargettableObject(self):
     speakTo(self.actor, MUDObject(None), "foo")
     assert self.actor.delegate.received == [UnfoundObjectEvent()]
Esempio n. 20
0
def test_register():
    obj = MUDObject(None)
    obj.addDelegate(DelegateHelper(obj))
Esempio n. 21
0
def test_register():
    obj = MUDObject(None)
    obj.addDelegate(DelegateHelper(obj))
Esempio n. 22
0
def test_equality():
    m = MUDObject(None)
    assert m == m
    assert MUDObject(None) != m
Esempio n. 23
0
 def setUp(self):
     self.obj = MUDObject(None)
     self.obj.addDelegate(DelegateHelper(self.obj))
Esempio n. 24
0
def test_hashability():
    s = set([MUDObject(None), MUDObject(None)])
    assert len(s) == 2
Esempio n. 25
0
 def setUp(self):
     self.obj = MUDObject(None)
     self.setup_for_object(self.obj)
Esempio n. 26
0
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
Esempio n. 27
0
 def setUp(self):
     self.obj = MUDObject(None)
     self.obj.addDelegate(DelegateHelper(self.obj))
Esempio n. 28
0
def test_deafness_turning_on():
    obj = MUDObject(None)
    deafOn(obj)
    assert obj.deaf