test_cursor.py 文件源码

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

项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码
def test_max(self, test_db):
        await test_db.test.create_index([('j', ASCENDING)])

        await test_db.test.insert_many([{'j': j, 'k': j} for j in range(10)])

        cursor = test_db.test.find().max([('j', 3)])
        assert len(await cursor.to_list()) == 3

        # Tuple.
        cursor = test_db.test.find().max((('j', 3),))
        assert len(await cursor.to_list()) == 3

        # Compound index.
        await test_db.test.create_index([('j', ASCENDING), ('k', ASCENDING)])
        cursor = test_db.test.find().max([('j', 3), ('k', 3)])
        assert len(await cursor.to_list()) == 3

        # Wrong order.
        cursor = test_db.test.find().max([('k', 3), ('j', 3)])
        with pytest.raises(OperationFailure):
            await cursor.to_list()

        # No such index.
        cursor = test_db.test.find().max([('k', 3)])
        with pytest.raises(OperationFailure):
            await cursor.to_list()

        with pytest.raises(TypeError):
            test_db.test.find().max(10)

        with pytest.raises(TypeError):
            test_db.test.find().max({'j': 10})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号