test_cursor.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号