Exemple #1
0
    def test_receiveFor(self):
        """
        You can subscribe to the events that are received by a particular
        object.
        """
        ev = MagicMock()
        world = World(ev)

        obj = world.create('foo')
        called = []
        world.receiveFor(obj['id'], called.append)
        world.eventReceived('event', obj['id'])

        self.assertEqual(called, ['event'])
        called.pop()

        world.stopReceivingFor(obj['id'], called.append)
        world.eventReceived('foo', obj['id'])

        self.assertEqual(called, [], "Should not receive")
Exemple #2
0
    def test_receiveFor(self):
        """
        You can subscribe to the events that are received by a particular
        object.
        """
        ev = MagicMock()
        world = World(ev)

        obj = world.create('foo')
        called = []
        world.receiveFor(obj['id'], called.append)
        world.eventReceived('event', obj['id'])

        self.assertEqual(called, ['event'])
        called.pop()

        world.stopReceivingFor(obj['id'], called.append)
        world.eventReceived('foo', obj['id'])

        self.assertEqual(called, [], "Should not receive")
Exemple #3
0
    def test_setGamePiece(self):
        """
        Connecting an avatar to a game piece will make the avatar subscribe
        to the events of that game piece.
        """
        world = World(MagicMock())

        a = Avatar(world)
        a.eventReceived = MagicMock()

        piece = world.create('foo', receive_emissions=False)
        a.setGamePiece(piece['id'])
        self.assertEqual(a._game_piece, piece['id'])

        world.eventReceived('hey', piece['id'])
        a.eventReceived.assert_called_once_with('hey')

        a.eventReceived.reset_mock()
        world.emit('foo', piece['id'])
        self.assertEqual(
            a.eventReceived.call_count, 0, "Should only receive "
            "things the game piece receives, not subscribe to "
            "things the game piece emits.")