test_cursor.py 文件源码

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

项目:aiomongo 作者: ZeoAlliance 项目源码 文件源码
def test_hint(self, test_db):
        with pytest.raises(TypeError):
            test_db.test.find().hint(3.5)
        await test_db.test.drop()

        await test_db.test.insert_many([{'num': i, 'foo': i} for i in range(100)])

        with pytest.raises(OperationFailure):
            await test_db.test.find({'num': 17, 'foo': 17}).hint([('num', ASCENDING)]).explain()

        with pytest.raises(OperationFailure):
            await test_db.test.find({'num': 17, 'foo': 17}).hint([('foo', ASCENDING)]).explain()

        spec = [('num', DESCENDING)]
        await test_db.test.create_index(spec)

        first = await self._next(test_db.test.find())
        assert 0 == first.get('num')
        first = await self._next(test_db.test.find().hint(spec))
        assert 99 == first.get('num')
        with pytest.raises(OperationFailure):
            await test_db.test.find({'num': 17, 'foo': 17}).hint([('foo', ASCENDING)]).explain()

        a = test_db.test.find({'num': 17})
        a.hint(spec)
        async for _ in a:
            break

        with pytest.raises(InvalidOperation):
            a.hint(spec)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号