Exemple #1
0
    def test_onEvent_cancel(self):
        """
        You can cancel the deferred returned by onEvent
        """
        world = World(MagicMock())

        obj = world.create('foo')

        d = world.onEvent(obj['id'], 'hey')
        d.cancel()

        world.emit('hey', obj['id'])

        self.assertFailure(d, defer.CancelledError)
Exemple #2
0
    def test_onEvent_cancel(self):
        """
        You can cancel the deferred returned by onEvent
        """
        world = World(MagicMock())

        obj = world.create('foo')

        d = world.onEvent(obj['id'], 'hey')
        d.cancel()

        world.emit('hey', obj['id'])

        self.assertFailure(d, defer.CancelledError)
Exemple #3
0
    def test_onEvent(self):
        """
        You can be notified when a certain event happens.
        """
        world = World(MagicMock())

        obj = world.create('foo')['id']

        d = world.onEvent(obj, 'event')
        self.assertEqual(d.called, False)

        world.emit('event', obj)
        self.assertEqual(self.successResultOf(d), 'event')

        # shouldn't die calling again
        world.emit('event', obj)
Exemple #4
0
    def test_onEvent(self):
        """
        You can be notified when a certain event happens.
        """
        world = World(MagicMock())

        obj = world.create('foo')['id']

        d = world.onEvent(obj, 'event')
        self.assertEqual(d.called, False)

        world.emit('event', obj)
        self.assertEqual(self.successResultOf(d), 'event')

        # shouldn't die calling again
        world.emit('event', obj)
Exemple #5
0
    def test_creator_dead(self):
        """
        When the creator of energy is dead, the energy is also dead.

        XXX I'm not sure if this belongs in the game engine or not.  Seems like
        a rule that could be changed.
        """
        world = World(MagicMock())
        thing = world.create('thing')

        Charge(thing['id']).execute(world)

        energy = thing['energy'][0]
        d = world.onEvent(energy, Destroyed(energy))

        # to die means to move to None
        Move(thing['id'], None).execute(world)

        self.assertEqual(d.called, True, "Energy should be destroyed because "
                         "the creator of the energy died.")
Exemple #6
0
    def test_creator_dead(self):
        """
        When the creator of energy is dead, the energy is also dead.

        XXX I'm not sure if this belongs in the game engine or not.  Seems like
        a rule that could be changed.
        """
        world = World(MagicMock())
        thing = world.create('thing')

        Charge(thing['id']).execute(world)

        energy = thing['energy'][0]
        d = world.onEvent(energy, Destroyed(energy))

        # to die means to move to None
        Move(thing['id'], None).execute(world)

        self.assertEqual(
            d.called, True, "Energy should be destroyed because "
            "the creator of the energy died.")