35
35
)
36
36
37
37
pytestmark = pytest .mark .anyio
38
- FAKER = faker .Faker ()
39
38
40
39
41
40
@pytest .mark .parametrize ("ack" , get_args (AckMode ))
42
- async def test_client_subscribtions_lifespan_resubscribe (ack : AckMode ) -> None :
41
+ async def test_client_subscribtions_lifespan_resubscribe (ack : AckMode , faker : faker . Faker ) -> None :
43
42
connection_class , collected_frames = create_spying_connection (* get_read_frames_with_lifespan ([CONNECTED_FRAME ], []))
44
43
client = EnrichedClient (connection_class = connection_class )
45
- sub_destination , message_destination , message_body = FAKER .pystr (), FAKER .pystr (), FAKER .binary (length = 10 )
46
- sub_extra_headers = FAKER .pydict (value_types = [str ])
44
+ sub_destination , message_destination , message_body = faker .pystr (), faker .pystr (), faker .binary (length = 10 )
45
+ sub_extra_headers = faker .pydict (value_types = [str ])
47
46
48
47
async with client :
49
48
subscription = await client .subscribe (
@@ -79,13 +78,15 @@ async def test_client_subscribtions_lifespan_resubscribe(ack: AckMode) -> None:
79
78
)
80
79
81
80
82
- async def test_client_subscribtions_lifespan_no_active_subs_in_aexit (monkeypatch : pytest .MonkeyPatch ) -> None :
81
+ async def test_client_subscribtions_lifespan_no_active_subs_in_aexit (
82
+ monkeypatch : pytest .MonkeyPatch , faker : faker .Faker
83
+ ) -> None :
83
84
monkeypatch .setattr (
84
85
stompman .subscription ,
85
86
"_make_subscription_id" ,
86
- mock .Mock (side_effect = [(first_id := FAKER .pystr ()), (second_id := FAKER .pystr ())]),
87
+ mock .Mock (side_effect = [(first_id := faker .pystr ()), (second_id := faker .pystr ())]),
87
88
)
88
- first_destination , second_destination = FAKER .pystr (), FAKER .pystr ()
89
+ first_destination , second_destination = faker .pystr (), faker .pystr ()
89
90
connection_class , collected_frames = create_spying_connection (* get_read_frames_with_lifespan ([]))
90
91
91
92
async with EnrichedClient (connection_class = connection_class ) as client :
@@ -110,10 +111,11 @@ async def test_client_subscribtions_lifespan_no_active_subs_in_aexit(monkeypatch
110
111
@pytest .mark .parametrize ("direct_error" , [True , False ])
111
112
async def test_client_subscribtions_lifespan_with_active_subs_in_aexit (
112
113
monkeypatch : pytest .MonkeyPatch ,
114
+ faker : faker .Faker ,
113
115
* ,
114
116
direct_error : bool ,
115
117
) -> None :
116
- subscription_id , destination = FAKER .pystr (), FAKER .pystr ()
118
+ subscription_id , destination = faker .pystr (), faker .pystr ()
117
119
monkeypatch .setattr (stompman .subscription , "_make_subscription_id" , mock .Mock (return_value = subscription_id ))
118
120
connection_class , collected_frames = create_spying_connection (* get_read_frames_with_lifespan ([]))
119
121
@@ -140,11 +142,11 @@ async def test_client_subscribtions_lifespan_with_active_subs_in_aexit(
140
142
)
141
143
142
144
143
- async def test_client_listen_routing_ok (monkeypatch : pytest .MonkeyPatch ) -> None :
145
+ async def test_client_listen_routing_ok (monkeypatch : pytest .MonkeyPatch , faker : faker . Faker ) -> None :
144
146
monkeypatch .setattr (
145
147
stompman .subscription ,
146
148
"_make_subscription_id" ,
147
- mock .Mock (side_effect = [(first_sub_id := FAKER .pystr ()), (second_sub_id := FAKER .pystr ())]),
149
+ mock .Mock (side_effect = [(first_sub_id := faker .pystr ()), (second_sub_id := faker .pystr ())]),
148
150
)
149
151
connection_class , _ = create_spying_connection (
150
152
* get_read_frames_with_lifespan (
@@ -168,10 +170,10 @@ async def test_client_listen_routing_ok(monkeypatch: pytest.MonkeyPatch) -> None
168
170
on_heartbeat = (on_heartbeat := mock .Mock ()),
169
171
) as client :
170
172
first_subscription = await client .subscribe (
171
- FAKER .pystr (), handler = first_message_handler , on_suppressed_exception = first_error_handler
173
+ faker .pystr (), handler = first_message_handler , on_suppressed_exception = first_error_handler
172
174
)
173
175
second_subscription = await client .subscribe (
174
- FAKER .pystr (), handler = second_message_handler , on_suppressed_exception = second_error_handler
176
+ faker .pystr (), handler = second_message_handler , on_suppressed_exception = second_error_handler
175
177
)
176
178
await asyncio .sleep (0 )
177
179
await asyncio .sleep (0 )
@@ -191,9 +193,9 @@ async def test_client_listen_routing_ok(monkeypatch: pytest.MonkeyPatch) -> None
191
193
@pytest .mark .parametrize ("side_effect" , [None , SomeError ])
192
194
@pytest .mark .parametrize ("ack" , ["client" , "client-individual" ])
193
195
async def test_client_listen_unsubscribe_before_ack_or_nack (
194
- monkeypatch : pytest .MonkeyPatch , ack : AckMode , side_effect : object
196
+ monkeypatch : pytest .MonkeyPatch , faker : faker . Faker , ack : AckMode , side_effect : object
195
197
) -> None :
196
- subscription_id , destination = FAKER .pystr (), FAKER .pystr ()
198
+ subscription_id , destination = faker .pystr (), faker .pystr ()
197
199
monkeypatch .setattr (stompman .subscription , "_make_subscription_id" , mock .Mock (return_value = subscription_id ))
198
200
199
201
message_frame = build_dataclass (MessageFrame , headers = {"subscription" : subscription_id })
@@ -218,8 +220,10 @@ async def test_client_listen_unsubscribe_before_ack_or_nack(
218
220
219
221
@pytest .mark .parametrize ("ok" , [True , False ])
220
222
@pytest .mark .parametrize ("ack" , ["client" , "client-individual" ])
221
- async def test_client_listen_ack_nack_sent (monkeypatch : pytest .MonkeyPatch , ack : AckMode , * , ok : bool ) -> None :
222
- subscription_id , destination , message_id = FAKER .pystr (), FAKER .pystr (), FAKER .pystr ()
223
+ async def test_client_listen_ack_nack_sent (
224
+ monkeypatch : pytest .MonkeyPatch , faker : faker .Faker , ack : AckMode , * , ok : bool
225
+ ) -> None :
226
+ subscription_id , destination , message_id = faker .pystr (), faker .pystr (), faker .pystr ()
223
227
monkeypatch .setattr (stompman .subscription , "_make_subscription_id" , mock .Mock (return_value = subscription_id ))
224
228
225
229
message_frame = build_dataclass (
@@ -248,8 +252,8 @@ async def test_client_listen_ack_nack_sent(monkeypatch: pytest.MonkeyPatch, ack:
248
252
249
253
250
254
@pytest .mark .parametrize ("ok" , [True , False ])
251
- async def test_client_listen_auto_ack_nack (monkeypatch : pytest .MonkeyPatch , * , ok : bool ) -> None :
252
- subscription_id , destination , message_id = FAKER .pystr (), FAKER .pystr (), FAKER .pystr ()
255
+ async def test_client_listen_auto_ack_nack (monkeypatch : pytest .MonkeyPatch , faker : faker . Faker , * , ok : bool ) -> None :
256
+ subscription_id , destination , message_id = faker .pystr (), faker .pystr (), faker .pystr ()
253
257
monkeypatch .setattr (stompman .subscription , "_make_subscription_id" , mock .Mock (return_value = subscription_id ))
254
258
255
259
message_frame = build_dataclass (
@@ -274,7 +278,7 @@ async def test_client_listen_auto_ack_nack(monkeypatch: pytest.MonkeyPatch, *, o
274
278
)
275
279
276
280
277
- async def test_client_listen_raises_on_aexit (monkeypatch : pytest .MonkeyPatch ) -> None :
281
+ async def test_client_listen_raises_on_aexit (monkeypatch : pytest .MonkeyPatch , faker : faker . Faker ) -> None :
278
282
monkeypatch .setattr ("asyncio.sleep" , partial (asyncio .sleep , 0 ))
279
283
280
284
connection_class , _ = create_spying_connection (* get_read_frames_with_lifespan ([]))
@@ -286,7 +290,7 @@ async def close_connection_soon(client: stompman.Client) -> None:
286
290
287
291
with pytest .raises (ExceptionGroup ) as exc_info : # noqa: PT012
288
292
async with asyncio .TaskGroup () as task_group , EnrichedClient (connection_class = connection_class ) as client :
289
- await client .subscribe (FAKER .pystr (), noop_message_handler , on_suppressed_exception = noop_error_handler )
293
+ await client .subscribe (faker .pystr (), noop_message_handler , on_suppressed_exception = noop_error_handler )
290
294
task_group .create_task (close_connection_soon (client ))
291
295
292
296
assert len (exc_info .value .exceptions ) == 1
0 commit comments