MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_limit

Method test_limit

test/asynchronous/test_cursor.py:460–509  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

458 self.assertEqual(99, first.get("i"))
459
460 async def test_limit(self):
461 db = self.db
462
463 with self.assertRaises(TypeError):
464 db.test.find().limit(None) # type: ignore[arg-type]
465 with self.assertRaises(TypeError):
466 db.test.find().limit("hello") # type: ignore[arg-type]
467 with self.assertRaises(TypeError):
468 db.test.find().limit(5.5) # type: ignore[arg-type]
469 self.assertTrue((db.test.find()).limit(5))
470
471 await db.test.drop()
472 await db.test.insert_many([{"x": i} for i in range(100)])
473
474 count = 0
475 async for _ in db.test.find():
476 count += 1
477 self.assertEqual(count, 100)
478
479 count = 0
480 async for _ in db.test.find().limit(20):
481 count += 1
482 self.assertEqual(count, 20)
483
484 count = 0
485 async for _ in db.test.find().limit(99):
486 count += 1
487 self.assertEqual(count, 99)
488
489 count = 0
490 async for _ in db.test.find().limit(1):
491 count += 1
492 self.assertEqual(count, 1)
493
494 count = 0
495 async for _ in db.test.find().limit(0):
496 count += 1
497 self.assertEqual(count, 100)
498
499 count = 0
500 async for _ in db.test.find().limit(0).limit(50).limit(10):
501 count += 1
502 self.assertEqual(count, 10)
503
504 a = db.test.find()
505 a.limit(10)
506 async for _ in a:
507 break
508 with self.assertRaises(InvalidOperation):
509 a.limit(5)
510
511 async def test_max(self):
512 db = self.db

Callers

nothing calls this directly

Calls 4

limitMethod · 0.45
findMethod · 0.45
dropMethod · 0.45
insert_manyMethod · 0.45

Tested by

no test coverage detected