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

Method test_max

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

Source from the content-addressed store, hash-verified

501 a.limit(5)
502
503 def test_max(self):
504 db = self.db
505 db.test.drop()
506 j_index = [("j", ASCENDING)]
507 db.test.create_index(j_index)
508
509 db.test.insert_many([{"j": j, "k": j} for j in range(10)])
510
511 def find(max_spec, expected_index):
512 return db.test.find().max(max_spec).hint(expected_index)
513
514 cursor = find([("j", 3)], j_index)
515 self.assertEqual(len(cursor.to_list()), 3)
516
517 # Tuple.
518 cursor = find((("j", 3),), j_index)
519 self.assertEqual(len(cursor.to_list()), 3)
520
521 # Compound index.
522 index_keys = [("j", ASCENDING), ("k", ASCENDING)]
523 db.test.create_index(index_keys)
524 cursor = find([("j", 3), ("k", 3)], index_keys)
525 self.assertEqual(len(cursor.to_list()), 3)
526
527 # Wrong order.
528 cursor = find([("k", 3), ("j", 3)], index_keys)
529 with self.assertRaises(OperationFailure):
530 cursor.to_list()
531
532 # No such index.
533 cursor = find([("k", 3)], "k")
534 with self.assertRaises(OperationFailure):
535 cursor.to_list()
536 with self.assertRaises(TypeError):
537 db.test.find().max(10) # type: ignore[arg-type]
538 with self.assertRaises(TypeError):
539 db.test.find().max({"j": 10}) # type: ignore[arg-type]
540
541 def test_min(self):
542 db = self.db

Callers

nothing calls this directly

Calls 6

dropMethod · 0.45
create_indexMethod · 0.45
insert_manyMethod · 0.45
to_listMethod · 0.45
maxMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected