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

Method test_contextlib

test/test_client.py:1425–1444  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1423 self.assertIn("pymongo_test_bernie", dbs)
1424
1425 def test_contextlib(self):
1426 client = self.rs_or_single_client()
1427 client.pymongo_test.drop_collection("test")
1428 client.pymongo_test.test.insert_one({"foo": "bar"})
1429
1430 # The socket used for the previous commands has been returned to the
1431 # pool
1432 self.assertEqual(1, len((get_pool(client)).conns))
1433
1434 # contextlib async support was added in Python 3.10
1435 if _IS_SYNC or sys.version_info >= (3, 10):
1436 with contextlib.closing(client):
1437 self.assertEqual("bar", (client.pymongo_test.test.find_one())["foo"])
1438 with self.assertRaises(InvalidOperation):
1439 client.pymongo_test.test.find_one()
1440 client = self.rs_or_single_client()
1441 with client as client:
1442 self.assertEqual("bar", (client.pymongo_test.test.find_one())["foo"])
1443 with self.assertRaises(InvalidOperation):
1444 client.pymongo_test.test.find_one()
1445
1446 @client_context.require_sync
1447 def test_interrupt_signal(self):

Callers

nothing calls this directly

Calls 5

get_poolFunction · 0.90
rs_or_single_clientMethod · 0.80
drop_collectionMethod · 0.45
insert_oneMethod · 0.45
find_oneMethod · 0.45

Tested by

no test coverage detected