예제 #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)