示例#1
0
 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
示例#2
0
文件: test_timer.py 项目: Scalr/kombu
 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
示例#3
0
    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)
示例#4
0
 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 == []
示例#5
0
 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
示例#6
0
    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
示例#7
0
 def test_eq(self):
     x = Entry(lambda x: 1)
     y = Entry(lambda x: 1)
     assert x == x
     assert x != y
示例#8
0
 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)
示例#9
0
 def test_hash(self):
     assert hash(Entry(lambda: None))
示例#10
0
 def test_repr(self):
     tref = Entry(lambda x: x(1, ), {})
     assert repr(tref)
示例#11
0
 def test_call(self):
     fun = Mock(name='fun')
     tref = Entry(fun, (4, 4), {'moo': 'baz'})
     tref()
     fun.assert_called_with(4, 4, moo='baz')
示例#12
0
 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)