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

Method test_find_w_regex

test/test_collection.py:1154–1167  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1152 self.assertIn("mike", db.test.find_one(projection={"x": 0}))
1153
1154 def test_find_w_regex(self):
1155 db = self.db
1156 db.test.delete_many({})
1157
1158 db.test.insert_one({"x": "hello_world"})
1159 db.test.insert_one({"x": "hello_mike"})
1160 db.test.insert_one({"x": "hello_mikey"})
1161 db.test.insert_one({"x": "hello_test"})
1162
1163 self.assertEqual(len(db.test.find().to_list()), 4)
1164 self.assertEqual(len(db.test.find({"x": re.compile("^hello.*")}).to_list()), 4)
1165 self.assertEqual(len(db.test.find({"x": re.compile("ello")}).to_list()), 4)
1166 self.assertEqual(len(db.test.find({"x": re.compile("^hello$")}).to_list()), 0)
1167 self.assertEqual(len(db.test.find({"x": re.compile("^hello_mi.*$")}).to_list()), 2)
1168
1169 def test_id_can_be_anything(self):
1170 db = self.db

Callers

nothing calls this directly

Calls 4

delete_manyMethod · 0.45
insert_oneMethod · 0.45
to_listMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected