(self)
| 547 | db.test.find().max({"j": 10}) # type: ignore[arg-type] |
| 548 | |
| 549 | async def test_min(self): |
| 550 | db = self.db |
| 551 | await db.test.drop() |
| 552 | j_index = [("j", ASCENDING)] |
| 553 | await db.test.create_index(j_index) |
| 554 | |
| 555 | await db.test.insert_many([{"j": j, "k": j} for j in range(10)]) |
| 556 | |
| 557 | def find(min_spec, expected_index): |
| 558 | return db.test.find().min(min_spec).hint(expected_index) |
| 559 | |
| 560 | cursor = find([("j", 3)], j_index) |
| 561 | self.assertEqual(len(await cursor.to_list()), 7) |
| 562 | |
| 563 | # Tuple. |
| 564 | cursor = find((("j", 3),), j_index) |
| 565 | self.assertEqual(len(await cursor.to_list()), 7) |
| 566 | |
| 567 | # Compound index. |
| 568 | index_keys = [("j", ASCENDING), ("k", ASCENDING)] |
| 569 | await db.test.create_index(index_keys) |
| 570 | cursor = find([("j", 3), ("k", 3)], index_keys) |
| 571 | self.assertEqual(len(await cursor.to_list()), 7) |
| 572 | |
| 573 | # Wrong order. |
| 574 | cursor = find([("k", 3), ("j", 3)], index_keys) |
| 575 | with self.assertRaises(OperationFailure): |
| 576 | await cursor.to_list() |
| 577 | |
| 578 | # No such index. |
| 579 | cursor = find([("k", 3)], "k") |
| 580 | with self.assertRaises(OperationFailure): |
| 581 | await cursor.to_list() |
| 582 | |
| 583 | with self.assertRaises(TypeError): |
| 584 | db.test.find().min(10) # type: ignore[arg-type] |
| 585 | with self.assertRaises(TypeError): |
| 586 | db.test.find().min({"j": 10}) # type: ignore[arg-type] |
| 587 | |
| 588 | async def test_min_max_without_hint(self): |
| 589 | coll = self.db.test |
nothing calls this directly
no test coverage detected