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)
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)
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.")
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.")