31
31
_IS_SYNC = False
32
32
33
33
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
-
45
34
class AsyncTestComment (AsyncIntegrationTest ):
46
35
async def _test_ops (
47
36
self ,
48
37
helpers ,
49
38
already_supported ,
50
39
listener ,
51
- db = Empty (), # noqa: B008
52
- coll = Empty (), # noqa: B008
53
40
):
54
41
for h , args in helpers :
55
42
c = "testing comment with " + h .__name__
56
43
with self .subTest ("collection-" + h .__name__ + "-comment" ):
57
44
for cc in [c , {"key" : c }, ["any" , 1 ]]:
58
45
listener .reset ()
59
46
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
79
51
self .assertIn (
80
52
"comment" ,
81
53
inspect .signature (h ).parameters ,
@@ -95,7 +67,7 @@ async def _test_ops(
95
67
self .assertEqual (cc , i .command ["comment" ])
96
68
tested = True
97
69
self .assertTrue (tested )
98
- if h not in [ coll . aggregate_raw_batches ] :
70
+ if h . __name__ != " aggregate_raw_batches" :
99
71
self .assertIn (
100
72
":param comment:" ,
101
73
h .__doc__ ,
@@ -128,9 +100,7 @@ async def test_database_helpers(self):
128
100
(db .dereference , [DBRef ("collection" , 1 )]),
129
101
]
130
102
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 )
134
104
135
105
@async_client_context .require_version_min (4 , 7 , - 1 )
136
106
@async_client_context .require_replica_set
@@ -186,7 +156,7 @@ async def test_collection_helpers(self):
186
156
coll .find_one_and_delete ,
187
157
coll .find_one_and_update ,
188
158
]
189
- await self ._test_ops (helpers , already_supported , listener , coll = coll , db = db )
159
+ await self ._test_ops (helpers , already_supported , listener )
190
160
191
161
192
162
if __name__ == "__main__" :
0 commit comments