Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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.")
Exemplo n.º 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.")