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

Method test_limit

test/test_cursor.py:452–501  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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