Skip to content

Commit ab48ce8

Browse files
committed
Format tests
1 parent c016123 commit ab48ce8

File tree

4 files changed

+75
-47
lines changed

4 files changed

+75
-47
lines changed

tests/codegen/test_validation.py

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
def 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+
"""
2223
operations:
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):
3133
def 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+
"""
3538
asyncapi: 3.0.0
3639
channels:
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):
6367
def 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+
"""
6772
asyncapi: 3.0.0
6873
channels:
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):
98104
def 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+
"""
102109
asyncapi: 3.0.0
103110
channels:
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):
126134
def 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+
"""
130139
asyncapi: 3.0.0
131140
channels:
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]:
194204
def 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+
"""
198209
asyncapi: 3.0.0
199210
channels:
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):
221233
def 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+
"""
225238
asyncapi: 3.0.0
226239
channels:
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

250266
def 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+
"""
254271
asyncapi: 3.0.0
255272
channels:
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

274294
def 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+
"""
278299
asyncapi: 3.0.0
279300
channels:
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):
302324
def 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+
"""
306329
asyncapi: 3.0.0
307330
channels:
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

345367
def 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+
"""
349372
asyncapi: 3.0.0
350373
channels:
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):
385409
def 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+
"""
389414
asyncapi: 3.0.0
390415
channels:
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):
418444
def 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+
"""
422449
asyncapi: 3.0.0
423450
channels:
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)

tests/codegen/test_validation_system.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ class TestValidationContext:
141141
def test_create_context(self):
142142
"""Test creating validation context."""
143143
spec = {"asyncapi": "3.0.0", "channels": {}}
144-
ctx = ValidationContext(
145-
spec=spec, spec_path=Path("test.yaml"), operations=None
146-
)
144+
ctx = ValidationContext(spec=spec, spec_path=Path("test.yaml"), operations=None)
147145

148146
assert ctx.spec == spec
149147
assert ctx.spec_path == Path("test.yaml")
@@ -418,6 +416,7 @@ def test_validate_spec_fail_on_error_false(self):
418416

419417
def test_validate_spec_with_categories(self):
420418
"""Test validate_spec with specific categories."""
419+
421420
# Register a test rule in a custom category
422421
@rule("custom-test")
423422
def custom_rule(ctx):

tests/core/endpoint/test_parameterized_subscriptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ async def test_subscriber_accepts_parameters():
133133

134134
# Create a minimal module for codec factory with messages.json structure
135135
import types
136+
136137
test_module = types.SimpleNamespace()
137138
test_module.messages = types.SimpleNamespace()
138139
test_module.messages.json = types.SimpleNamespace()
@@ -201,6 +202,7 @@ async def test_subscriber_wildcard_parameters_flow_to_wire():
201202
wire = InMemoryWire()
202203

203204
import types
205+
204206
test_module = types.SimpleNamespace()
205207
test_module.messages = types.SimpleNamespace()
206208
test_module.messages.json = types.SimpleNamespace()
@@ -286,6 +288,7 @@ async def test_queue_binding_with_wildcards_raises_error():
286288
from asyncapi_python.contrib.wire.amqp import AmqpWire
287289

288290
import types
291+
289292
test_module = types.SimpleNamespace()
290293

291294
# This would fail at runtime when creating consumer
@@ -348,6 +351,7 @@ async def test_default_empty_parameters():
348351
wire = InMemoryWire()
349352

350353
import types
354+
351355
test_module = types.SimpleNamespace()
352356
test_module.messages = types.SimpleNamespace()
353357
test_module.messages.json = types.SimpleNamespace()
@@ -414,6 +418,7 @@ async def test_subscriber_rejects_missing_parameters():
414418
wire = AmqpWire("amqp://guest:guest@localhost")
415419

416420
import types
421+
417422
test_module = types.SimpleNamespace()
418423
test_module.messages = types.SimpleNamespace()
419424
test_module.messages.json = types.SimpleNamespace()
@@ -527,6 +532,7 @@ async def test_subscriber_rejects_extra_parameters():
527532
wire = AmqpWire("amqp://guest:guest@localhost")
528533

529534
import types
535+
530536
test_module = types.SimpleNamespace()
531537
test_module.messages = types.SimpleNamespace()
532538
test_module.messages.json = types.SimpleNamespace()

tests/core/wire/test_amqp_utils.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ def test_accepts_exact_match(self):
4747
)
4848

4949
# Should not raise
50-
validate_parameters_strict(
51-
channel, {"location": "NYC", "severity": "high"}
52-
)
50+
validate_parameters_strict(channel, {"location": "NYC", "severity": "high"})
5351

5452
def test_rejects_missing_parameters(self):
5553
"""Should raise ValueError when required parameters are missing."""
@@ -85,9 +83,7 @@ def test_rejects_extra_parameters(self):
8583
channel = create_test_channel("weather.{location}", ["location"])
8684

8785
with pytest.raises(ValueError) as exc_info:
88-
validate_parameters_strict(
89-
channel, {"location": "NYC", "severity": "high"}
90-
)
86+
validate_parameters_strict(channel, {"location": "NYC", "severity": "high"})
9187

9288
error_msg = str(exc_info.value)
9389
assert "Unexpected parameters" in error_msg
@@ -149,13 +145,14 @@ def test_rejects_mixed_missing_and_extra(self):
149145
with pytest.raises(ValueError) as exc_info:
150146
# Missing: severity
151147
# Extra: priority
152-
validate_parameters_strict(
153-
channel, {"location": "NYC", "priority": "high"}
154-
)
148+
validate_parameters_strict(channel, {"location": "NYC", "priority": "high"})
155149

156150
error_msg = str(exc_info.value)
157151
# Should fail on missing first (that's the implementation order)
158-
assert "Missing required parameters" in error_msg or "Unexpected parameters" in error_msg
152+
assert (
153+
"Missing required parameters" in error_msg
154+
or "Unexpected parameters" in error_msg
155+
)
159156

160157

161158
class TestSubstituteParameters:
@@ -190,9 +187,7 @@ def test_handles_no_parameters(self):
190187
def test_fails_on_missing_parameter(self):
191188
"""Should raise ValueError when template has placeholder without value."""
192189
with pytest.raises(ValueError) as exc_info:
193-
substitute_parameters(
194-
"weather.{location}.{severity}", {"location": "NYC"}
195-
)
190+
substitute_parameters("weather.{location}.{severity}", {"location": "NYC"})
196191

197192
error_msg = str(exc_info.value)
198193
assert "undefined parameters" in error_msg

0 commit comments

Comments
 (0)