Skip to content

Commit

Permalink
Coverage: Adds some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Jun 22, 2016
1 parent 8beb2ee commit 05bbb54
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ omit =
*kombu/transport/sqlalchemy/*
*kombu/utils.compat.py
*kombu/utils/eventio.py
*kombu/async/debug.py
*kombu/transport/amqplib.py
*kombu/transport/couchdb.py
*kombu/transport/beanstalk.py
Expand Down
56 changes: 56 additions & 0 deletions kombu/tests/async/test_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import errno

from vine import promise

from kombu.async import hub as _hub
from kombu.async import Hub, READ, WRITE, ERR
from kombu.async.debug import callback_for, repr_flag, _rcb
Expand Down Expand Up @@ -184,6 +186,20 @@ def test_stop(self):
self.hub.stop()
self.hub.call_soon.assert_called_with(_raise_stop_error)

@patch('kombu.async.hub.promise')
def test_call_soon(self, promise):
callback = Mock(name='callback')
ret = self.hub.call_soon(callback, 1, 2, 3)
promise.assert_called_with(callback, (1, 2, 3))
self.assertIn(promise(), self.hub._ready)
self.assertIs(ret, promise())

def test_call_soon__promise_argument(self):
callback = promise(Mock(name='callback'), (1, 2, 3))
ret = self.hub.call_soon(callback)
self.assertIs(ret, callback)
self.assertIn(ret, self.hub._ready)

def test_call_later(self):
callback = Mock(name='callback')
self.hub.timer = Mock(name='hub.timer')
Expand Down Expand Up @@ -318,6 +334,12 @@ def test_remove_reader(self):
self.assertNotIn(2, self.hub.readers)
self.assertIn(2, self.hub.writers)

def test_remove_reader__not_writeable(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), READ)
self.hub.remove_reader(2)
self.assertNotIn(2, self.hub.readers)

def test_remove_writer(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), READ)
Expand All @@ -326,6 +348,12 @@ def test_remove_writer(self):
self.assertIn(2, self.hub.readers)
self.assertNotIn(2, self.hub.writers)

def test_remove_writer__not_readable(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), WRITE)
self.hub.remove_writer(2)
self.assertNotIn(2, self.hub.writers)

def test_add__consolidate(self):
self.hub.poller = Mock(name='hub.poller')
self.hub.add(2, Mock(), WRITE, consolidate=True)
Expand Down Expand Up @@ -477,3 +505,31 @@ def test_enter__exit(self):
def test_scheduler_property(self):
hub = Hub(timer=[1, 2, 3])
self.assertEqual(list(hub.scheduler), [1, 2, 3])

def test_loop__tick_callbacks(self):
self.hub._ready = Mock(name='_ready')
self.hub._ready.pop.side_effect = RuntimeError()
ticks = [Mock(name='cb1'), Mock(name='cb2')]
self.hub.on_tick = list(ticks)

with self.assertRaises(RuntimeError):
next(self.hub.loop)

ticks[0].assert_called_once_with()
ticks[1].assert_called_once_with()

def test_loop__todo(self):
self.hub.fire_timers = Mock(name='fire_timers')
self.hub.fire_timers.side_effect = RuntimeError()
self.hub.timer = Mock(name='timer')

callbacks = [Mock(name='cb1'), Mock(name='cb2')]
for cb in callbacks:
self.hub.call_soon(cb)
self.hub._ready.add(None)

with self.assertRaises(RuntimeError):
next(self.hub.loop)

callbacks[0].assert_called_once_with()
callbacks[1].assert_called_once_with()
7 changes: 6 additions & 1 deletion kombu/tests/async/test_timer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import, unicode_literals

from datetime import datetime

from kombu.five import bytes_if_py2

from kombu.async.timer import Entry, Timer, to_timestamp
Expand All @@ -9,9 +11,12 @@

class test_to_timestamp(Case):

def test_to_timestamp(self):
def test_timestamp(self):
self.assertIs(to_timestamp(3.13), 3.13)

def test_datetime(self):
self.assertTrue(to_timestamp(datetime.utcnow()))


class test_Entry(Case):

Expand Down

0 comments on commit 05bbb54

Please sign in to comment.