1818def test_validation_error_raised_for_missing_asyncapi_field (tmp_path : Path ):
1919 """Test that missing asyncapi field raises ValidationError."""
2020 spec_file = tmp_path / "invalid.yaml"
21- spec_file .write_text ("""
21+ spec_file .write_text (
22+ """
2223operations:
2324 myOp:
2425 action: send
25- """ )
26+ """
27+ )
2628
2729 with pytest .raises (ValueError , match = "Missing 'asyncapi' version field" ):
2830 extract_all_operations (spec_file )
@@ -31,7 +33,8 @@ def test_validation_error_raised_for_missing_asyncapi_field(tmp_path: Path):
3133def test_validation_error_for_invalid_channel_parameters (tmp_path : Path ):
3234 """Test that parameters not in address raise ValidationError."""
3335 spec_file = tmp_path / "invalid_params.yaml"
34- spec_file .write_text ("""
36+ spec_file .write_text (
37+ """
3538asyncapi: 3.0.0
3639channels:
3740 myChannel:
@@ -49,7 +52,8 @@ def test_validation_error_for_invalid_channel_parameters(tmp_path: Path):
4952 action: send
5053 channel:
5154 $ref: '#/channels/myChannel'
52- """ )
55+ """
56+ )
5357
5458 with pytest .raises (ValidationError ) as exc_info :
5559 extract_all_operations (spec_file )
@@ -63,7 +67,8 @@ def test_validation_error_for_invalid_channel_parameters(tmp_path: Path):
6367def test_validation_passes_for_valid_spec (tmp_path : Path ):
6468 """Test that a valid spec passes validation."""
6569 spec_file = tmp_path / "valid.yaml"
66- spec_file .write_text ("""
70+ spec_file .write_text (
71+ """
6772asyncapi: 3.0.0
6873channels:
6974 userChannel:
@@ -88,7 +93,8 @@ def test_validation_passes_for_valid_spec(tmp_path: Path):
8893 $ref: '#/channels/userChannel'
8994 messages:
9095 - $ref: '#/channels/userChannel/messages/userMessage'
91- """ )
96+ """
97+ )
9298
9399 # Should not raise
94100 operations = extract_all_operations (spec_file )
@@ -98,7 +104,8 @@ def test_validation_passes_for_valid_spec(tmp_path: Path):
98104def test_validation_can_be_disabled (tmp_path : Path ):
99105 """Test that validation can be disabled."""
100106 spec_file = tmp_path / "invalid_params.yaml"
101- spec_file .write_text ("""
107+ spec_file .write_text (
108+ """
102109asyncapi: 3.0.0
103110channels:
104111 myChannel:
@@ -116,7 +123,8 @@ def test_validation_can_be_disabled(tmp_path: Path):
116123 action: send
117124 channel:
118125 $ref: '#/channels/myChannel'
119- """ )
126+ """
127+ )
120128
121129 # Should not raise when validation is disabled
122130 operations = extract_all_operations (spec_file , validate = False )
@@ -126,7 +134,8 @@ def test_validation_can_be_disabled(tmp_path: Path):
126134def test_warnings_do_not_fail_validation (tmp_path : Path ):
127135 """Test that warnings are collected but don't fail validation."""
128136 spec_file = tmp_path / "with_warnings.yaml"
129- spec_file .write_text ("""
137+ spec_file .write_text (
138+ """
130139asyncapi: 3.0.0
131140channels:
132141 myChannel:
@@ -149,7 +158,8 @@ def test_warnings_do_not_fail_validation(tmp_path: Path):
149158 action: send
150159 channel:
151160 $ref: '#/channels/myChannel'
152- """ )
161+ """
162+ )
153163
154164 # Should not raise - location warning doesn't fail
155165 operations = extract_all_operations (spec_file )
@@ -194,7 +204,8 @@ def custom_test_rule(ctx: ValidationContext) -> list[ValidationIssue]:
194204def test_parameter_with_location_warns_not_implemented (tmp_path : Path ):
195205 """Test that using location field generates a warning."""
196206 spec_file = tmp_path / "location.yaml"
197- spec_file .write_text ("""
207+ spec_file .write_text (
208+ """
198209asyncapi: 3.0.0
199210channels:
200211 myChannel:
@@ -211,7 +222,8 @@ def test_parameter_with_location_warns_not_implemented(tmp_path: Path):
211222 action: send
212223 channel:
213224 $ref: '#/channels/myChannel'
214- """ )
225+ """
226+ )
215227
216228 # Should succeed but print warning
217229 operations = extract_all_operations (spec_file , fail_on_error = False )
@@ -221,7 +233,8 @@ def test_parameter_with_location_warns_not_implemented(tmp_path: Path):
221233def test_undefined_placeholders_in_address (tmp_path : Path ):
222234 """Test that undefined placeholders in address raise error."""
223235 spec_file = tmp_path / "undefined_params.yaml"
224- spec_file .write_text ("""
236+ spec_file .write_text (
237+ """
225238asyncapi: 3.0.0
226239channels:
227240 myChannel:
@@ -239,18 +252,22 @@ def test_undefined_placeholders_in_address(tmp_path: Path):
239252 action: send
240253 channel:
241254 $ref: '#/channels/myChannel'
242- """ )
255+ """
256+ )
243257
244258 with pytest .raises (ValidationError ) as exc_info :
245259 extract_all_operations (spec_file )
246260
247- assert any ("undefined parameters" in error .message for error in exc_info .value .errors )
261+ assert any (
262+ "undefined parameters" in error .message for error in exc_info .value .errors
263+ )
248264
249265
250266def test_operation_references_nonexistent_channel (tmp_path : Path ):
251267 """Test that operation referencing non-existent channel raises error."""
252268 spec_file = tmp_path / "bad_channel_ref.yaml"
253- spec_file .write_text ("""
269+ spec_file .write_text (
270+ """
254271asyncapi: 3.0.0
255272channels:
256273 realChannel:
@@ -264,17 +281,21 @@ def test_operation_references_nonexistent_channel(tmp_path: Path):
264281 action: send
265282 channel:
266283 $ref: '#/channels/fakeChannel'
267- """ )
284+ """
285+ )
268286
269287 # Parser will fail when trying to resolve $ref (before validation runs)
270- with pytest .raises (RuntimeError , match = "JSON pointer segment 'fakeChannel' not found" ):
288+ with pytest .raises (
289+ RuntimeError , match = "JSON pointer segment 'fakeChannel' not found"
290+ ):
271291 extract_all_operations (spec_file )
272292
273293
274294def test_invalid_operation_action (tmp_path : Path ):
275295 """Test that invalid operation action raises error."""
276296 spec_file = tmp_path / "bad_action.yaml"
277- spec_file .write_text ("""
297+ spec_file .write_text (
298+ """
278299asyncapi: 3.0.0
279300channels:
280301 myChannel:
@@ -288,7 +309,8 @@ def test_invalid_operation_action(tmp_path: Path):
288309 action: publish
289310 channel:
290311 $ref: '#/channels/myChannel'
291- """ )
312+ """
313+ )
292314
293315 with pytest .raises (ValidationError ) as exc_info :
294316 extract_all_operations (spec_file )
@@ -302,7 +324,8 @@ def test_invalid_operation_action(tmp_path: Path):
302324def test_amqp_parameterized_channel_without_binding_type_fails (tmp_path : Path ):
303325 """Test that parameterized channel without AMQP binding type fails validation."""
304326 spec_file = tmp_path / "amqp_no_binding_type.yaml"
305- spec_file .write_text ("""
327+ spec_file .write_text (
328+ """
306329asyncapi: 3.0.0
307330channels:
308331 weatherAlerts:
@@ -332,20 +355,20 @@ def test_amqp_parameterized_channel_without_binding_type_fails(tmp_path: Path):
332355 action: send
333356 channel:
334357 $ref: '#/channels/weatherAlerts'
335- """ )
358+ """
359+ )
336360
337361 with pytest .raises (ValidationError ) as exc_info :
338362 extract_all_operations (spec_file )
339363
340- assert any (
341- "lacks 'is' field" in error .message for error in exc_info .value .errors
342- )
364+ assert any ("lacks 'is' field" in error .message for error in exc_info .value .errors )
343365
344366
345367def test_amqp_parameterized_channel_with_routing_key_passes (tmp_path : Path ):
346368 """Test that parameterized channel with is: routingKey passes validation."""
347369 spec_file = tmp_path / "amqp_routing_key.yaml"
348- spec_file .write_text ("""
370+ spec_file .write_text (
371+ """
349372asyncapi: 3.0.0
350373channels:
351374 weatherAlerts:
@@ -375,7 +398,8 @@ def test_amqp_parameterized_channel_with_routing_key_passes(tmp_path: Path):
375398 action: send
376399 channel:
377400 $ref: '#/channels/weatherAlerts'
378- """ )
401+ """
402+ )
379403
380404 # Should not raise
381405 operations = extract_all_operations (spec_file )
@@ -385,7 +409,8 @@ def test_amqp_parameterized_channel_with_routing_key_passes(tmp_path: Path):
385409def test_amqp_parameterized_channel_with_queue_passes (tmp_path : Path ):
386410 """Test that parameterized channel with is: queue passes validation."""
387411 spec_file = tmp_path / "amqp_queue.yaml"
388- spec_file .write_text ("""
412+ spec_file .write_text (
413+ """
389414asyncapi: 3.0.0
390415channels:
391416 userNotifications:
@@ -408,7 +433,8 @@ def test_amqp_parameterized_channel_with_queue_passes(tmp_path: Path):
408433 action: send
409434 channel:
410435 $ref: '#/channels/userNotifications'
411- """ )
436+ """
437+ )
412438
413439 # Should not raise
414440 operations = extract_all_operations (spec_file )
@@ -418,7 +444,8 @@ def test_amqp_parameterized_channel_with_queue_passes(tmp_path: Path):
418444def test_amqp_parameterized_channel_with_invalid_binding_type_fails (tmp_path : Path ):
419445 """Test that parameterized channel with invalid binding type fails validation."""
420446 spec_file = tmp_path / "amqp_invalid_type.yaml"
421- spec_file .write_text ("""
447+ spec_file .write_text (
448+ """
422449asyncapi: 3.0.0
423450channels:
424451 myChannel:
@@ -441,7 +468,8 @@ def test_amqp_parameterized_channel_with_invalid_binding_type_fails(tmp_path: Pa
441468 action: send
442469 channel:
443470 $ref: '#/channels/myChannel'
444- """ )
471+ """
472+ )
445473
446474 with pytest .raises (ValidationError ) as exc_info :
447475 extract_all_operations (spec_file )
0 commit comments