MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / test_getitem_numeric_index

Method test_getitem_numeric_index

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

Source from the content-addressed store, hash-verified

1071 # Cursors don't support slicing
1072 @client_context.require_sync
1073 def test_getitem_numeric_index(self):
1074 self.db.drop_collection("test")
1075 self.db.test.insert_many([{"i": i} for i in range(100)])
1076
1077 self.assertEqual(0, self.db.test.find()[0]["i"])
1078 self.assertEqual(50, self.db.test.find()[50]["i"])
1079 self.assertEqual(50, self.db.test.find().skip(50)[0]["i"])
1080 self.assertEqual(50, self.db.test.find().skip(49)[1]["i"])
1081 self.assertEqual(50, self.db.test.find()[50]["i"])
1082 self.assertEqual(99, self.db.test.find()[99]["i"])
1083
1084 self.assertRaises(IndexError, lambda x: self.db.test.find()[x], -1)
1085 self.assertRaises(IndexError, lambda x: self.db.test.find()[x], 100)
1086 self.assertRaises(IndexError, lambda x: self.db.test.find().skip(50)[x], 50)
1087
1088 @client_context.require_sync
1089 def test_iteration_with_list(self):

Callers

nothing calls this directly

Calls 4

drop_collectionMethod · 0.45
insert_manyMethod · 0.45
findMethod · 0.45
skipMethod · 0.45

Tested by

no test coverage detected