Skip to content

Commit 9e0f409

Browse files
committed
remove Empty class and cleanup _test_ops funciton
1 parent 69b5ce0 commit 9e0f409

File tree

2 files changed

+14
-72
lines changed

2 files changed

+14
-72
lines changed

test/asynchronous/test_comment.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,51 +31,23 @@
3131
_IS_SYNC = False
3232

3333

34-
class Empty:
35-
def __getattr__(self, item):
36-
try:
37-
self.__dict__[item]
38-
except KeyError:
39-
return self.empty
40-
41-
def empty(self, *args, **kwargs):
42-
return Empty()
43-
44-
4534
class AsyncTestComment(AsyncIntegrationTest):
4635
async def _test_ops(
4736
self,
4837
helpers,
4938
already_supported,
5039
listener,
51-
db=Empty(), # noqa: B008
52-
coll=Empty(), # noqa: B008
5340
):
5441
for h, args in helpers:
5542
c = "testing comment with " + h.__name__
5643
with self.subTest("collection-" + h.__name__ + "-comment"):
5744
for cc in [c, {"key": c}, ["any", 1]]:
5845
listener.reset()
5946
kwargs = {"comment": cc}
60-
if h == coll.rename:
61-
await db.get_collection("temp_temp_temp").drop()
62-
destruct_coll = db.get_collection("test_temp")
63-
await destruct_coll.insert_one({})
64-
maybe_cursor = await destruct_coll.rename(*args, **kwargs)
65-
await destruct_coll.drop()
66-
elif h == db.validate_collection:
67-
coll = db.get_collection("test")
68-
await coll.insert_one({})
69-
maybe_cursor = await db.validate_collection(*args, **kwargs)
70-
else:
71-
if not _IS_SYNC and isinstance(coll, Empty):
72-
coll.create_index("a")
73-
else:
74-
await coll.create_index("a")
75-
if not _IS_SYNC and iscoroutinefunction(h):
76-
maybe_cursor = await h(*args, **kwargs)
77-
else:
78-
maybe_cursor = h(*args, **kwargs)
47+
try:
48+
maybe_cursor = await h(*args, **kwargs)
49+
except Exception:
50+
maybe_cursor = None
7951
self.assertIn(
8052
"comment",
8153
inspect.signature(h).parameters,
@@ -95,7 +67,7 @@ async def _test_ops(
9567
self.assertEqual(cc, i.command["comment"])
9668
tested = True
9769
self.assertTrue(tested)
98-
if h not in [coll.aggregate_raw_batches]:
70+
if h.__name__ != "aggregate_raw_batches":
9971
self.assertIn(
10072
":param comment:",
10173
h.__doc__,
@@ -128,9 +100,7 @@ async def test_database_helpers(self):
128100
(db.dereference, [DBRef("collection", 1)]),
129101
]
130102
already_supported = [db.command, db.list_collections, db.list_collection_names]
131-
await self._test_ops(
132-
helpers, already_supported, listener, db=db, coll=db.get_collection("test")
133-
)
103+
await self._test_ops(helpers, already_supported, listener)
134104

135105
@async_client_context.require_version_min(4, 7, -1)
136106
@async_client_context.require_replica_set
@@ -186,7 +156,7 @@ async def test_collection_helpers(self):
186156
coll.find_one_and_delete,
187157
coll.find_one_and_update,
188158
]
189-
await self._test_ops(helpers, already_supported, listener, coll=coll, db=db)
159+
await self._test_ops(helpers, already_supported, listener)
190160

191161

192162
if __name__ == "__main__":

test/test_comment.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,51 +31,23 @@
3131
_IS_SYNC = True
3232

3333

34-
class Empty:
35-
def __getattr__(self, item):
36-
try:
37-
self.__dict__[item]
38-
except KeyError:
39-
return self.empty
40-
41-
def empty(self, *args, **kwargs):
42-
return Empty()
43-
44-
4534
class TestComment(IntegrationTest):
4635
def _test_ops(
4736
self,
4837
helpers,
4938
already_supported,
5039
listener,
51-
db=Empty(), # noqa: B008
52-
coll=Empty(), # noqa: B008
5340
):
5441
for h, args in helpers:
5542
c = "testing comment with " + h.__name__
5643
with self.subTest("collection-" + h.__name__ + "-comment"):
5744
for cc in [c, {"key": c}, ["any", 1]]:
5845
listener.reset()
5946
kwargs = {"comment": cc}
60-
if h == coll.rename:
61-
db.get_collection("temp_temp_temp").drop()
62-
destruct_coll = db.get_collection("test_temp")
63-
destruct_coll.insert_one({})
64-
maybe_cursor = destruct_coll.rename(*args, **kwargs)
65-
destruct_coll.drop()
66-
elif h == db.validate_collection:
67-
coll = db.get_collection("test")
68-
coll.insert_one({})
69-
maybe_cursor = db.validate_collection(*args, **kwargs)
70-
else:
71-
if not _IS_SYNC and isinstance(coll, Empty):
72-
coll.create_index("a")
73-
else:
74-
coll.create_index("a")
75-
if not _IS_SYNC and iscoroutinefunction(h):
76-
maybe_cursor = h(*args, **kwargs)
77-
else:
78-
maybe_cursor = h(*args, **kwargs)
47+
try:
48+
maybe_cursor = h(*args, **kwargs)
49+
except Exception:
50+
maybe_cursor = None
7951
self.assertIn(
8052
"comment",
8153
inspect.signature(h).parameters,
@@ -95,7 +67,7 @@ def _test_ops(
9567
self.assertEqual(cc, i.command["comment"])
9668
tested = True
9769
self.assertTrue(tested)
98-
if h not in [coll.aggregate_raw_batches]:
70+
if h.__name__ != "aggregate_raw_batches":
9971
self.assertIn(
10072
":param comment:",
10173
h.__doc__,
@@ -128,7 +100,7 @@ def test_database_helpers(self):
128100
(db.dereference, [DBRef("collection", 1)]),
129101
]
130102
already_supported = [db.command, db.list_collections, db.list_collection_names]
131-
self._test_ops(helpers, already_supported, listener, db=db, coll=db.get_collection("test"))
103+
self._test_ops(helpers, already_supported, listener)
132104

133105
@client_context.require_version_min(4, 7, -1)
134106
@client_context.require_replica_set
@@ -184,7 +156,7 @@ def test_collection_helpers(self):
184156
coll.find_one_and_delete,
185157
coll.find_one_and_update,
186158
]
187-
self._test_ops(helpers, already_supported, listener, coll=coll, db=db)
159+
self._test_ops(helpers, already_supported, listener)
188160

189161

190162
if __name__ == "__main__":

0 commit comments

Comments
 (0)