Skip to content

Commit

Permalink
Merge pull request #70 from TurboGears/mim_conn_context_mgr
Browse files Browse the repository at this point in the history
MIM: Connection supports `with` like pymongo MongoClient does
  • Loading branch information
dill0wn authored Dec 19, 2024
2 parents c4fdb38 + e26ea07 commit 17e04aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ming/mim.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def _is_writable(self):
def is_mongos(self):
return False

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb) -> None:
self.close()

class Database(database.Database):
def __init__(self, client, name, **__):
Expand Down
10 changes: 10 additions & 0 deletions ming/tests/test_mim.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ def test_search(self):
assert coll.count_documents({'$text': {'$search': 'searched'}}) == 1


class TestConnection(TestCase):

def setUp(self):
self.conn = create_datastore('mim:///testdb').conn

def test_context_manager(self):
with self.conn:
pass


class TestDottedOperators(TestCase):

def setUp(self):
Expand Down

0 comments on commit 17e04aa

Please sign in to comment.