def test_time_with_encoding(create_redis, server, loop): redis = yield from create_redis(server.tcp_address, loop=loop, encoding='utf-8') res = yield from redis.time() assert isinstance(res, float) pytest.assert_almost_equal(int(res), int(time.time()), delta=10)
def test_almost(self): from pytest import assert_almost_equal, assert_not_almost_equal assert_almost_equal(1, 1.00001, 4) assert_not_almost_equal(1, 1.01, 3) pytest.raises(AssertionError, assert_almost_equal, 1, 1.01, 5) pytest.raises(AssertionError, assert_not_almost_equal, 1, 1.00001, 2)
def test_pttl(redis, server): yield from add(redis, 'key', 'val') res = yield from redis.pttl('key') assert res == -1 res = yield from redis.pttl('non-existent-key') if server.version < (2, 8, 0): assert res == -1 else: assert res == -2 yield from redis.pexpire('key', 500) res = yield from redis.pttl('key') pytest.assert_almost_equal(res, 500, -2) with pytest.raises(TypeError): yield from redis.pttl(None)
def test_pexpireat(redis): yield from add(redis, 'my-key', 123) now = math.ceil((yield from redis.time()) * 1000) fut1 = redis.pexpireat('my-key', now + 2000) fut2 = redis.ttl('my-key') fut3 = redis.pttl('my-key') assert (yield from fut1) is True assert (yield from fut2) == 2 pytest.assert_almost_equal((yield from fut3), 2000, -3) with pytest.raises(TypeError): yield from redis.pexpireat(None, 1234) with pytest.raises(TypeError): yield from redis.pexpireat('key', 'timestamp') with pytest.raises(TypeError): yield from redis.pexpireat('key', 1000.0)
async def test_pexpireat(redis): await add(redis, 'my-key', 123) now = math.ceil((await redis.time()) * 1000) fut1 = redis.pexpireat('my-key', now + 2000) fut2 = redis.ttl('my-key') fut3 = redis.pttl('my-key') assert (await fut1) is True assert (await fut2) == 2 pytest.assert_almost_equal((await fut3), 2000, -3) with pytest.raises(TypeError): await redis.pexpireat(None, 1234) with pytest.raises(TypeError): await redis.pexpireat('key', 'timestamp') with pytest.raises(TypeError): await redis.pexpireat('key', 1000.0)
def test_pexpireat(redis): yield from add(redis, 'my-key', 123) now = math.ceil((yield from redis.time()) * 1000) res = yield from redis.pexpireat('my-key', now + 800) assert res is True res = yield from redis.ttl('my-key') assert res == 1 res = yield from redis.pttl('my-key') pytest.assert_almost_equal(res, 800, -2) with pytest.raises(TypeError): yield from redis.pexpireat(None, 1234) with pytest.raises(TypeError): yield from redis.pexpireat('key', 'timestamp') with pytest.raises(TypeError): yield from redis.pexpireat('key', 1000.0)
def test_pexpireat(redis): yield from add(redis, 'my-key', 123) now = math.ceil((yield from redis.time()) * 1000) res = yield from redis.pexpireat('my-key', now + 500) assert res is True res = yield from redis.ttl('my-key') assert res == 1 res = yield from redis.pttl('my-key') pytest.assert_almost_equal(res, 500, -2) with pytest.raises(TypeError): yield from redis.pexpireat(None, 1234) with pytest.raises(TypeError): yield from redis.pexpireat('key', 'timestamp') with pytest.raises(TypeError): yield from redis.pexpireat('key', 1000.0)
async def test_time(redis): res = await redis.time() assert isinstance(res, float) pytest.assert_almost_equal(int(res), int(time.time()), delta=10)
async def test_time_with_encoding(create_redis, server, loop): redis = await create_redis(server.tcp_address, loop=loop, encoding='utf-8') res = await redis.time() assert isinstance(res, float) pytest.assert_almost_equal(int(res), int(time.time()), delta=10)