(self)
| 588 | coll.find().max([("j", 3)]).to_list() |
| 589 | |
| 590 | def test_batch_size(self): |
| 591 | db = self.db |
| 592 | db.test.drop() |
| 593 | db.test.insert_many([{"x": x} for x in range(200)]) |
| 594 | |
| 595 | with self.assertRaises(TypeError): |
| 596 | db.test.find().batch_size(None) # type: ignore[arg-type] |
| 597 | with self.assertRaises(TypeError): |
| 598 | db.test.find().batch_size("hello") # type: ignore[arg-type] |
| 599 | with self.assertRaises(TypeError): |
| 600 | db.test.find().batch_size(5.5) # type: ignore[arg-type] |
| 601 | with self.assertRaises(ValueError): |
| 602 | db.test.find().batch_size(-1) |
| 603 | self.assertTrue((db.test.find()).batch_size(5)) |
| 604 | a = db.test.find() |
| 605 | for _ in a: |
| 606 | break |
| 607 | self.assertRaises(InvalidOperation, a.batch_size, 5) |
| 608 | |
| 609 | def cursor_count(cursor, expected_count): |
| 610 | count = 0 |
| 611 | for _ in cursor: |
| 612 | count += 1 |
| 613 | self.assertEqual(expected_count, count) |
| 614 | |
| 615 | cursor_count((db.test.find()).batch_size(0), 200) |
| 616 | cursor_count((db.test.find()).batch_size(1), 200) |
| 617 | cursor_count((db.test.find()).batch_size(2), 200) |
| 618 | cursor_count((db.test.find()).batch_size(5), 200) |
| 619 | cursor_count((db.test.find()).batch_size(100), 200) |
| 620 | cursor_count((db.test.find()).batch_size(500), 200) |
| 621 | |
| 622 | cursor_count((db.test.find()).batch_size(0).limit(1), 1) |
| 623 | cursor_count((db.test.find()).batch_size(1).limit(1), 1) |
| 624 | cursor_count((db.test.find()).batch_size(2).limit(1), 1) |
| 625 | cursor_count((db.test.find()).batch_size(5).limit(1), 1) |
| 626 | cursor_count((db.test.find()).batch_size(100).limit(1), 1) |
| 627 | cursor_count((db.test.find()).batch_size(500).limit(1), 1) |
| 628 | |
| 629 | cursor_count((db.test.find()).batch_size(0).limit(10), 10) |
| 630 | cursor_count((db.test.find()).batch_size(1).limit(10), 10) |
| 631 | cursor_count((db.test.find()).batch_size(2).limit(10), 10) |
| 632 | cursor_count((db.test.find()).batch_size(5).limit(10), 10) |
| 633 | cursor_count((db.test.find()).batch_size(100).limit(10), 10) |
| 634 | cursor_count((db.test.find()).batch_size(500).limit(10), 10) |
| 635 | |
| 636 | cur = db.test.find().batch_size(1) |
| 637 | next(cur) |
| 638 | # find command batchSize should be 1 |
| 639 | self.assertEqual(0, len(cur._data)) |
| 640 | next(cur) |
| 641 | self.assertEqual(0, len(cur._data)) |
| 642 | next(cur) |
| 643 | self.assertEqual(0, len(cur._data)) |
| 644 | next(cur) |
| 645 | self.assertEqual(0, len(cur._data)) |
| 646 | |
| 647 | def test_limit_and_batch_size(self): |
nothing calls this directly
no test coverage detected