From ecf1457f138a94ae2fcc9fd769593c0a5581671b Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Wed, 25 Sep 2013 16:48:00 +0100 Subject: Tests passing --- docs/reference/kombu.rst | 2 +- kombu/tests/test_connection.py | 10 ++++++---- kombu/tests/transport/test_librabbitmq.py | 17 ++++++---------- kombu/tests/transport/test_pyamqp.py | 16 ++++++---------- kombu/tests/transport/test_redis.py | 32 ++++++++++++++++--------------- 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/docs/reference/kombu.rst b/docs/reference/kombu.rst index 3c63ba92..67a5eca1 100644 --- a/docs/reference/kombu.rst +++ b/docs/reference/kombu.rst @@ -41,7 +41,6 @@ .. autoattribute:: cycle .. autoattribute:: host .. autoattribute:: manager - .. autoattribute:: eventmap .. autoattribute:: supports_heartbeats .. autoattribute:: is_evented @@ -65,6 +64,7 @@ .. automethod:: maybe_switch_next .. automethod:: heartbeat_check .. automethod:: maybe_close_channel + .. automethod:: register_with_event_loop .. automethod:: close .. automethod:: _close .. automethod:: completes_cycle diff --git a/kombu/tests/test_connection.py b/kombu/tests/test_connection.py index 2e04891d..8a6afff0 100644 --- a/kombu/tests/test_connection.py +++ b/kombu/tests/test_connection.py @@ -297,11 +297,13 @@ class test_Connection(Case): c.transport.supports_ev = False self.assertFalse(c.is_evented) - def test_eventmap(self): + def test_register_with_event_loop(self): c = Connection(transport=Mock) - c.transport.eventmap.return_value = {1: 1, 2: 2} - self.assertDictEqual(c.eventmap, {1: 1, 2: 2}) - c.transport.eventmap.assert_called_with(c.connection) + loop = Mock(name='loop') + c.register_with_event_loop(loop) + c.transport.register_with_event_loop.assert_called_with( + c.connection, loop, + ) def test_manager(self): c = Connection(transport=Mock) diff --git a/kombu/tests/transport/test_librabbitmq.py b/kombu/tests/transport/test_librabbitmq.py index 09601962..53c00376 100644 --- a/kombu/tests/transport/test_librabbitmq.py +++ b/kombu/tests/transport/test_librabbitmq.py @@ -129,19 +129,14 @@ class test_Transport(lrmqCase): self.T._collect(conn) close.assert_called_with(conn.fileno()) - def test_eventmap(self): - conn = Mock() - self.assertDictEqual( - self.T.eventmap(conn), - {conn.fileno(): self.client.drain_nowait}, + def test_register_with_event_loop(self): + conn = Mock(name='conn') + loop = Mock(name='loop') + self.T.register_with_event_loop(conn, loop) + loop.add_reader.assert_called_with( + conn.fileno(), self.T.client.drain_nowait_all, ) - def test_on_poll_start(self): - self.assertDictEqual(self.T.on_poll_start(), {}) - - def test_on_poll_init(self): - self.T.on_poll_init(poller=Mock(name='poller')) - def test_verify_connection(self): conn = Mock(name='connection') conn.connected = True diff --git a/kombu/tests/transport/test_pyamqp.py b/kombu/tests/transport/test_pyamqp.py index 9b948ed6..c688b94c 100644 --- a/kombu/tests/transport/test_pyamqp.py +++ b/kombu/tests/transport/test_pyamqp.py @@ -157,19 +157,15 @@ class test_pyamqp(Case): c = Connection(port=1337, transport=Transport).connect() self.assertEqual(c['host'], '127.0.0.1:1337') - def test_eventmap(self): + def test_register_with_event_loop(self): t = pyamqp.Transport(Mock()) - conn = Mock() - self.assertDictEqual( - t.eventmap(conn), - {conn.sock: t.client.drain_nowait}, + conn = Mock(name='conn') + loop = Mock(name='loop') + t.register_with_event_loop(conn, loop) + loop.add_reader.assert_called_with( + conn.sock, t.client.drain_nowait_all, ) - def test_event_interface(self): - t = pyamqp.Transport(Mock()) - t.on_poll_init(Mock()) - t.on_poll_start() - def test_heartbeat_check(self): t = pyamqp.Transport(Mock()) conn = Mock() diff --git a/kombu/tests/transport/test_redis.py b/kombu/tests/transport/test_redis.py index bac799b6..a85f4e8e 100644 --- a/kombu/tests/transport/test_redis.py +++ b/kombu/tests/transport/test_redis.py @@ -638,23 +638,25 @@ class test_Channel(Case): self.channel.pool.release.assert_called_with(client.connection) cc.assert_called_with() - def test_transport_on_poll_init(self): + def test_register_with_event_loop(self): transport = self.connection.transport - transport.cycle = Mock(name='cyle') - poller = Mock(name='poller') - redis.Transport.on_poll_init(transport, poller) - transport.cycle.on_poll_init.assert_called_with(poller) + transport.cycle = Mock(name='cycle') + transport.cycle.fds = {12: 'LISTEN', 13: 'BRPOP'} + conn = Mock(name='conn') + loop = Mock(name='loop') + redis.Transport.register_with_event_loop(transport, conn, loop) + transport.cycle.on_poll_init.assert_called_with(loop.poller) + loop.call_repeatedly.assert_called_with( + 10, transport.cycle.maybe_restore_messages, + ) + self.assertTrue(loop.on_tick.add.called) + on_poll_start = loop.on_tick.add.call_args[0][0] - def test_transport_on_poll_start(self): - transport = self.connection.transport - cycle = transport.cycle = Mock(name='cyle') - cycle.fds = {12: 'LISTEN', 13: 'BRPOP'} - res = redis.Transport.on_poll_start(transport) - cycle.on_poll_start.assert_called_with() - self.assertDictEqual(res, { - 12: transport.handle_event, - 13: transport.handle_event, - }) + on_poll_start() + transport.cycle.on_poll_start.assert_called_with() + loop.add_reader.assert_has_calls([ + call(12, transport.handle_event), call(13, transport.handle_event), + ]) def test_transport_handle_event(self): transport = self.connection.transport -- cgit v1.2.1