Skip to content

Commit 14fc4a3

Browse files
committed
Fix flake8
1 parent b235ae2 commit 14fc4a3

File tree

3 files changed

+59
-61
lines changed

3 files changed

+59
-61
lines changed

tests/test_Admin.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,86 +1530,85 @@ class UninitializedAdmin(AdminClient):
15301530
def __init__(self, config):
15311531
# Don't call super().__init__() - leaves self->rk as NULL
15321532
pass
1533-
1533+
15341534
admin = UninitializedAdmin({})
1535-
1536-
1535+
15371536
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15381537
admin.create_topics([NewTopic("test", 1, 1)])
1539-
1538+
15401539
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15411540
admin.delete_topics(["test"])
1542-
1541+
15431542
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15441543
admin.create_partitions([NewPartitions("test", 2)])
1545-
1544+
15461545
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15471546
admin.describe_configs([ConfigResource(ResourceType.TOPIC, "test")])
1548-
1547+
15491548
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15501549
admin.incremental_alter_configs([ConfigResource(ResourceType.TOPIC, "test")])
1551-
1550+
15521551
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15531552
admin.alter_configs([ConfigResource(ResourceType.TOPIC, "test")])
1554-
1553+
15551554
acl_binding = AclBinding(
15561555
ResourceType.TOPIC, "topic1", ResourcePatternType.LITERAL,
15571556
"User:u1", "*", AclOperation.WRITE, AclPermissionType.ALLOW
15581557
)
1559-
1558+
15601559
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15611560
admin.create_acls([acl_binding])
1562-
1561+
15631562
acl_filter = AclBindingFilter(ResourceType.ANY, None, ResourcePatternType.ANY,
1564-
None, None, AclOperation.ANY, AclPermissionType.ANY)
1565-
1563+
None, None, AclOperation.ANY, AclPermissionType.ANY)
1564+
15661565
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15671566
admin.delete_acls([acl_filter])
1568-
1567+
15691568
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15701569
admin.describe_acls(acl_filter)
1571-
1570+
15721571
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15731572
admin.list_consumer_groups()
1574-
1573+
15751574
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15761575
admin.describe_user_scram_credentials(["user"])
1577-
1576+
15781577
scram_info = ScramCredentialInfo(ScramMechanism.SCRAM_SHA_256, 10000)
15791578
upsertion = UserScramCredentialUpsertion("user", scram_info, b"password")
1580-
1579+
15811580
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15821581
admin.alter_user_scram_credentials([upsertion])
1583-
1582+
15841583
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15851584
admin.describe_consumer_groups(["group"])
1586-
1585+
15871586
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15881587
admin.describe_topics(TopicCollection(["topic"]))
1589-
1588+
15901589
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15911590
admin.describe_cluster()
1592-
1591+
15931592
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15941593
admin.delete_consumer_groups(["group"])
1595-
1594+
15961595
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
15971596
admin.list_consumer_group_offsets([ConsumerGroupTopicPartitions("group")])
1598-
1597+
15991598
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
16001599
admin.alter_consumer_group_offsets([ConsumerGroupTopicPartitions("group", [TopicPartition("topic", 0, 5)])])
1601-
1600+
16021601
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
16031602
admin.list_offsets({TopicPartition("topic", 0, 10): OffsetSpec.earliest()})
1604-
1603+
16051604
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
16061605
admin.delete_records([TopicPartition("topic", 0, 10)])
1607-
1606+
16081607
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
16091608
admin.elect_leaders(ElectionType.PREFERRED, [TopicPartition("topic", 0)])
1610-
1609+
16111610
with pytest.raises(RuntimeError, match="AdminClient has been closed"):
16121611
admin.poll(0.001)
1613-
1612+
16141613
# Test __len__() - should return 0 for closed admin (safe, no crash)
16151614
assert len(admin) == 0

tests/test_Consumer.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -624,56 +624,55 @@ class UninitializedConsumer(Consumer):
624624
def __init__(self, config):
625625
# Don't call super().__init__() - leaves self->rk as NULL
626626
pass
627-
627+
628628
consumer = UninitializedConsumer({'group.id': 'test'})
629-
629+
630630
with pytest.raises(RuntimeError, match="Consumer closed"):
631631
consumer.subscribe(['topic'])
632-
632+
633633
with pytest.raises(RuntimeError, match="Consumer closed"):
634634
consumer.unsubscribe()
635-
635+
636636
with pytest.raises(RuntimeError, match="Consumer closed"):
637637
consumer.poll()
638-
638+
639639
with pytest.raises(RuntimeError, match="Consumer closed"):
640640
consumer.consume()
641-
641+
642642
with pytest.raises(RuntimeError, match="Consumer closed"):
643643
consumer.assign([TopicPartition('topic', 0)])
644-
644+
645645
with pytest.raises(RuntimeError, match="Consumer closed"):
646646
consumer.unassign()
647-
647+
648648
with pytest.raises(RuntimeError, match="Consumer closed"):
649649
consumer.assignment()
650-
650+
651651
with pytest.raises(RuntimeError, match="Consumer closed"):
652652
consumer.commit()
653-
653+
654654
with pytest.raises(RuntimeError, match="Consumer closed"):
655655
consumer.committed([TopicPartition('topic', 0)])
656-
656+
657657
with pytest.raises(RuntimeError, match="Consumer closed"):
658658
consumer.position([TopicPartition('topic', 0)])
659-
659+
660660
with pytest.raises(RuntimeError, match="Consumer closed"):
661661
consumer.seek(TopicPartition('topic', 0, 0))
662-
662+
663663
with pytest.raises(RuntimeError, match="Consumer closed"):
664664
consumer.get_watermark_offsets(TopicPartition('topic', 0))
665-
665+
666666
with pytest.raises(RuntimeError, match="Consumer closed"):
667667
consumer.store_offsets([TopicPartition('topic', 0, 42)])
668-
668+
669669
with pytest.raises(RuntimeError, match="Consumer closed"):
670670
consumer.offsets_for_times([TopicPartition('topic', 0)])
671-
671+
672672
with pytest.raises(RuntimeError, match="Handle has been closed"):
673673
consumer.list_topics()
674-
675674

676675
consumer.close() # Should succeed
677-
676+
678677
with pytest.raises(RuntimeError, match="Consumer closed"):
679678
consumer.consumer_group_metadata()

tests/test_Producer.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,51 +1347,51 @@ def on_delivery(err, msg):
13471347

13481348
def test_uninitialized_producer_methods():
13491349
"""Test that all Producer methods raise RuntimeError when called on uninitialized instance.
1350-
1350+
13511351
This test verifies issue #1590 fix - prevents SEGV when subclassing Producer
13521352
without calling super().__init__().
13531353
"""
13541354
class UninitializedProducer(Producer):
13551355
def __init__(self, config):
13561356
# Don't call super().__init__() - leaves self->rk as NULL
13571357
pass
1358-
1358+
13591359
producer = UninitializedProducer({})
1360-
1360+
13611361
with pytest.raises(RuntimeError, match="Producer has been closed"):
13621362
producer.produce('topic', value=b'test')
1363-
1363+
13641364
with pytest.raises(RuntimeError, match="Producer has been closed"):
13651365
producer.poll()
1366-
1366+
13671367
with pytest.raises(RuntimeError, match="Producer has been closed"):
13681368
producer.flush()
1369-
1369+
13701370
with pytest.raises(RuntimeError, match="Producer has been closed"):
13711371
producer.purge()
1372-
1372+
13731373
with pytest.raises(RuntimeError, match="Producer has been closed"):
13741374
producer.produce_batch('topic', [{'value': b'test'}])
1375-
1375+
13761376
with pytest.raises(RuntimeError, match="Producer has been closed"):
13771377
producer.init_transactions()
1378-
1378+
13791379
with pytest.raises(RuntimeError, match="Producer has been closed"):
13801380
producer.begin_transaction()
1381-
1381+
13821382
# send_offsets_to_transaction - NULL check happens after argument parsing
13831383
consumer = Consumer({'group.id': 'test', 'socket.timeout.ms': 10})
13841384
metadata = consumer.consumer_group_metadata()
13851385
consumer.close()
1386-
1386+
13871387
with pytest.raises(RuntimeError, match="Producer has been closed"):
13881388
producer.send_offsets_to_transaction([TopicPartition('topic', 0)], metadata)
1389-
1389+
13901390
with pytest.raises(RuntimeError, match="Producer has been closed"):
13911391
producer.commit_transaction()
1392-
1392+
13931393
with pytest.raises(RuntimeError, match="Producer has been closed"):
13941394
producer.abort_transaction()
1395-
1395+
13961396
# Test __len__() - should return 0 for closed producer (safe, no crash)
13971397
assert len(producer) == 0

0 commit comments

Comments
 (0)