def test_limit(self, test_db):
with pytest.raises(TypeError):
test_db.test.find().limit()
with pytest.raises(TypeError):
test_db.test.find().limit('hello')
with pytest.raises(TypeError):
test_db.test.find().limit(5.5)
assert test_db.test.find().limit(5)
await test_db.test.drop()
await test_db.test.insert_many([{'x': i} for i in range(100)])
count = 0
async for _ in test_db.test.find():
count += 1
assert count == 100
count = 0
async for _ in test_db.test.find().limit(20):
count += 1
assert count == 20
count = 0
async for _ in test_db.test.find().limit(99):
count += 1
assert count == 99
count = 0
async for _ in test_db.test.find().limit(1):
count += 1
assert count == 1
count = 0
async for _ in test_db.test.find().limit(0):
count += 1
assert count == 100
count = 0
async for _ in test_db.test.find().limit(0).limit(50).limit(10):
count += 1
assert count == 10
a = test_db.test.find()
a.limit(10)
async for _ in a:
break
with pytest.raises(InvalidOperation):
a.limit(5)
评论列表
文章目录