def test_cancel(self): tref = Entry(lambda x: x, (1, ), {}) assert not tref.canceled assert not tref.cancelled tref.cancel() assert tref.canceled assert tref.cancelled
def test_cancel(self): tref = Entry(lambda x: x, (1,), {}) assert not tref.canceled assert not tref.cancelled tref.cancel() assert tref.canceled assert tref.cancelled
def test_handle_error(self): on_error = Mock(name='on_error') s = Timer(on_error=on_error) with patch('kombu.asynchronous.timer.to_timestamp') as tot: tot.side_effect = OverflowError() s.enter_at(Entry(lambda: None, (), {}), eta=datetime.now()) s.enter_at(Entry(lambda: None, (), {}), eta=None) s.on_error = None with pytest.raises(OverflowError): s.enter_at(Entry(lambda: None, (), {}), eta=datetime.now()) on_error.assert_called_once() exc = on_error.call_args[0][0] assert isinstance(exc, OverflowError)
def test_redis_timer_clear(self): r = redis.StrictRedis() rt = RedisTimer(r) entry = Entry(lambda x: x) rt._enter(datetime.now(), 1, entry) rt.clear() assert rt.queue == []
def test_redis_timer_serialize_entry(self): r = redis.StrictRedis() rt = RedisTimer(r) fun = Mock(name='fun') entry = Entry(fun) info = { "instance": fun.__self__, "func": fun.__name__, "args": [], "kwargs": {} } assert rt._serialize_entry(entry) == info
def test_redis_timer_deserialize_entry(self): r = redis.StrictRedis() rt = RedisTimer(r) fun = Mock(name='fun') entry = Entry(fun) info = { "instance": fun.__self__, "func": fun.__name__, "args": [], "kwargs": {} } _entry = rt._deserialize_entry(info) assert _entry is not None assert entry.func == _entry.func assert entry.args == _entry.args assert entry.kwargs == _entry.kwargs
def test_eq(self): x = Entry(lambda x: 1) y = Entry(lambda x: 1) assert x == x assert x != y
def test_ordering(self): # we don't care about results, just that it's possible Entry(lambda x: 1) < Entry(lambda x: 2) Entry(lambda x: 1) > Entry(lambda x: 2) Entry(lambda x: 1) >= Entry(lambda x: 2) Entry(lambda x: 1) <= Entry(lambda x: 2)
def test_hash(self): assert hash(Entry(lambda: None))
def test_repr(self): tref = Entry(lambda x: x(1, ), {}) assert repr(tref)
def test_call(self): fun = Mock(name='fun') tref = Entry(fun, (4, 4), {'moo': 'baz'}) tref() fun.assert_called_with(4, 4, moo='baz')
def test_redis_timer_enter(self): r = redis.StrictRedis() rt = RedisTimer(r) entry = Entry(lambda x: x) assert entry is rt._enter(datetime.now(), 1, entry)