Skip to content

Commit 0798f7f

Browse files
committed
Fix linter
1 parent 3e4c8d4 commit 0798f7f

File tree

3 files changed

+95
-103
lines changed

3 files changed

+95
-103
lines changed

tests/test_Admin.py

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -658,20 +658,20 @@ def test_describe_topics_api():
658658

659659
# Wrong argument type
660660
for args in [
661-
[topic_names],
662-
["test-topic-1"],
663-
[TopicCollection([3])],
664-
[TopicCollection(["correct", 3])],
665-
[TopicCollection([None])]
666-
]:
661+
[topic_names],
662+
["test-topic-1"],
663+
[TopicCollection([3])],
664+
[TopicCollection(["correct", 3])],
665+
[TopicCollection([None])]
666+
]:
667667
with pytest.raises(TypeError):
668668
a.describe_topics(*args, **kwargs)
669669

670670
# Wrong argument value
671671
for args in [
672-
[TopicCollection([""])],
673-
[TopicCollection(["correct", ""])]
674-
]:
672+
[TopicCollection([""])],
673+
[TopicCollection(["correct", ""])]
674+
]:
675675
with pytest.raises(ValueError):
676676
a.describe_topics(*args, **kwargs)
677677

@@ -1053,13 +1053,13 @@ def test_list_offsets_api():
10531053

10541054
# Wrong option types
10551055
for kwargs in [
1056-
{
1057-
"isolation_level": 10
1058-
},
1059-
{
1060-
"request_timeout": "test"
1061-
}
1062-
]:
1056+
{
1057+
"isolation_level": 10
1058+
},
1059+
{
1060+
"request_timeout": "test"
1061+
}
1062+
]:
10631063
requests = {
10641064
TopicPartition("topic1", 0, 10): OffsetSpec.earliest()
10651065
}
@@ -1068,10 +1068,10 @@ def test_list_offsets_api():
10681068

10691069
# Wrong option values
10701070
for kwargs in [
1071-
{
1072-
"request_timeout": -1
1073-
}
1074-
]:
1071+
{
1072+
"request_timeout": -1
1073+
}
1074+
]:
10751075
requests = {
10761076
TopicPartition("topic1", 0, 10): OffsetSpec.earliest()
10771077
}
@@ -1095,13 +1095,13 @@ def test_list_offsets_api():
10951095

10961096
# Invalid TopicPartition
10971097
for requests in [
1098-
{
1099-
TopicPartition("", 0, 10): OffsetSpec.earliest()
1100-
},
1101-
{
1102-
TopicPartition("correct", -1, 10): OffsetSpec.earliest()
1103-
}
1104-
]:
1098+
{
1099+
TopicPartition("", 0, 10): OffsetSpec.earliest()
1100+
},
1101+
{
1102+
TopicPartition("correct", -1, 10): OffsetSpec.earliest()
1103+
}
1104+
]:
11051105
with pytest.raises(ValueError):
11061106
a.list_offsets(requests, **kwargs)
11071107

@@ -1131,33 +1131,33 @@ def test_list_offsets_api():
11311131

11321132
# Key isn't a TopicPartition
11331133
for requests in [
1134-
{
1135-
"not-topic-partition": OffsetSpec.latest()
1136-
},
1137-
{
1138-
TopicPartition("topic1", 0, 10): OffsetSpec.latest(),
1139-
"not-topic-partition": OffsetSpec.latest()
1140-
},
1141-
{
1142-
None: OffsetSpec.latest()
1143-
}
1144-
]:
1134+
{
1135+
"not-topic-partition": OffsetSpec.latest()
1136+
},
1137+
{
1138+
TopicPartition("topic1", 0, 10): OffsetSpec.latest(),
1139+
"not-topic-partition": OffsetSpec.latest()
1140+
},
1141+
{
1142+
None: OffsetSpec.latest()
1143+
}
1144+
]:
11451145
with pytest.raises(TypeError):
11461146
a.list_offsets(requests, **kwargs)
11471147

11481148
# Value isn't a OffsetSpec
11491149
for requests in [
1150-
{
1151-
TopicPartition("topic1", 0, 10): "test"
1152-
},
1153-
{
1154-
TopicPartition("topic1", 0, 10): OffsetSpec.latest(),
1155-
TopicPartition("topic1", 0, 10): "test"
1156-
},
1157-
{
1158-
TopicPartition("topic1", 0, 10): None
1159-
}
1160-
]:
1150+
{
1151+
TopicPartition("topic1", 0, 10): "test"
1152+
},
1153+
{
1154+
TopicPartition("topic1", 0, 10): OffsetSpec.latest(),
1155+
TopicPartition("topic1", 0, 10): "test"
1156+
},
1157+
{
1158+
TopicPartition("topic1", 0, 10): None
1159+
}
1160+
]:
11611161
with pytest.raises(TypeError):
11621162
a.list_offsets(requests, **kwargs)
11631163

@@ -1226,8 +1226,6 @@ def test_elect_leaders():
12261226
.result(timeout=1)
12271227

12281228

1229-
@pytest.mark.skipif(libversion()[1] < 0x000b0500,
1230-
reason="AdminAPI requires librdkafka >= v0.11.5")
12311229
def test_admin_callback_exception_no_system_error():
12321230
"""Test AdminClient callbacks exception handling with different exception types"""
12331231

@@ -1275,10 +1273,9 @@ def error_cb_runtime_error(error):
12751273
assert "RuntimeError from error_cb" in str(exc_info.value)
12761274

12771275

1278-
@pytest.mark.skipif(libversion()[1] < 0x000b0500,
1279-
reason="AdminAPI requires librdkafka >= v0.11.5")
12801276
def test_admin_multiple_callbacks_different_error_types():
1281-
"""Test AdminClient with multiple callbacks configured with different error types to see which one gets triggered"""
1277+
"""Test AdminClient with multiple callbacks configured with different error types
1278+
to see which one gets triggered"""
12821279

12831280
callbacks_called = []
12841281

@@ -1304,9 +1301,9 @@ def throttle_cb_that_raises_kafka(throttle_event):
13041301
})
13051302

13061303
# Test that error_cb callback raises an exception (it's triggered by connection failures)
1307-
with pytest.raises(RuntimeError) as exc_info:
1304+
with pytest.raises(RuntimeError):
13081305
admin.poll(timeout=0.2)
13091306

13101307
# Verify that error_cb was called
13111308
assert len(callbacks_called) > 0
1312-
assert 'error_cb_runtime' in callbacks_called
1309+
assert 'error_cb_runtime' in callbacks_called

tests/test_Consumer.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def test_callback_exception_no_system_error():
321321

322322
# Test error_cb callback
323323
error_called = []
324-
324+
325325
def error_cb_that_raises(error):
326326
"""Error callback that raises an exception"""
327327
error_called.append(error)
@@ -348,7 +348,7 @@ def error_cb_that_raises(error):
348348

349349
# Test stats_cb callback
350350
stats_called = []
351-
351+
352352
def stats_cb_that_raises(stats_json):
353353
"""Stats callback that raises an exception"""
354354
stats_called.append(stats_json)
@@ -376,7 +376,7 @@ def stats_cb_that_raises(stats_json):
376376

377377
# Test throttle_cb callback (may not be triggered in this scenario)
378378
throttle_called = []
379-
379+
380380
def throttle_cb_that_raises(throttle_event):
381381
"""Throttle callback that raises an exception"""
382382
throttle_called.append(throttle_event)
@@ -402,25 +402,25 @@ def throttle_cb_that_raises(throttle_event):
402402
if "Test exception from throttle_cb" in str(exc_info.value):
403403
assert len(throttle_called) > 0
404404
print("Throttle callback was triggered and raised exception")
405-
405+
406406
consumer3.close()
407407

408408

409409
def test_error_callback_exception_different_error_types():
410410
"""Test error callback with different exception types"""
411-
411+
412412
def error_cb_kafka_exception(error):
413413
"""Error callback that raises KafkaException"""
414414
raise KafkaException(error)
415-
415+
416416
def error_cb_value_error(error):
417417
"""Error callback that raises ValueError"""
418418
raise ValueError(f"Custom error: {error}")
419-
419+
420420
def error_cb_runtime_error(error):
421421
"""Error callback that raises RuntimeError"""
422422
raise RuntimeError(f"Runtime error: {error}")
423-
423+
424424
# Test with KafkaException
425425
consumer1 = TestConsumer({
426426
'group.id': 'test-kafka-exception',
@@ -430,11 +430,11 @@ def error_cb_runtime_error(error):
430430
'error_cb': error_cb_kafka_exception
431431
})
432432
consumer1.subscribe(['test-topic'])
433-
433+
434434
with pytest.raises(KafkaException):
435435
consumer1.consume(timeout=0.1)
436436
consumer1.close()
437-
437+
438438
# Test with ValueError
439439
consumer2 = TestConsumer({
440440
'group.id': 'test-value-error',
@@ -444,12 +444,12 @@ def error_cb_runtime_error(error):
444444
'error_cb': error_cb_value_error
445445
})
446446
consumer2.subscribe(['test-topic'])
447-
447+
448448
with pytest.raises(ValueError) as exc_info:
449449
consumer2.consume(timeout=0.1)
450450
assert "Custom error:" in str(exc_info.value)
451451
consumer2.close()
452-
452+
453453
# Test with RuntimeError
454454
consumer3 = TestConsumer({
455455
'group.id': 'test-runtime-error',
@@ -459,14 +459,8 @@ def error_cb_runtime_error(error):
459459
'error_cb': error_cb_runtime_error
460460
})
461461
consumer3.subscribe(['test-topic'])
462-
462+
463463
with pytest.raises(RuntimeError) as exc_info:
464464
consumer3.consume(timeout=0.1)
465465
assert "Runtime error:" in str(exc_info.value)
466466
consumer3.close()
467-
468-
469-
470-
471-
472-

0 commit comments

Comments
 (0)