Skip to content

Commit bd4baf5

Browse files
committed
Flake8 and Py2 fixes
1 parent e403698 commit bd4baf5

File tree

4 files changed

+66
-51
lines changed

4 files changed

+66
-51
lines changed

src/confluent_kafka/admin/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ def __init__(self, name, value,
6868
self.is_default = bool(is_default)
6969
"""Indicates whether the configuration property is using its default value."""
7070
self.is_sensitive = bool(is_sensitive)
71-
"""Indicates whether the configuration property value contains sensitive information (such as security settings), in which case .value is None."""
71+
"""
72+
Indicates whether the configuration property value contains
73+
sensitive information (such as security settings), in which
74+
case .value is None."""
7275
self.is_synonym = bool(is_synonym)
7376
"""Indicates whether the configuration property is a synonym for the parent configuration entry."""
7477
self.synonyms = synonyms
@@ -585,7 +588,7 @@ class GroupMember(object):
585588
`A Guide To The Kafka Protocol <https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-GroupMembershipAPI>`_.
586589
587590
This class is typically not user instantiated.
588-
"""
591+
""" # noqa: E501
589592
def __init__(self,):
590593
self.id = None
591594
"""Member id (generated by broker)."""

tests/integration/consumer/test_cooperative_rebalance_1.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,26 @@ def test_cooperative_rebalance_1(kafka_cluster):
3333
'enable.auto.commit': 'false',
3434
'auto.offset.reset': 'earliest',
3535
'heartbeat.interval.ms': '2000',
36-
'session.timeout.ms': '6000', # minimum allowed by broker
36+
'session.timeout.ms': '6000', # minimum allowed by broker
3737
'max.poll.interval.ms': '6500'}
3838

39-
assign_count = 0
40-
def on_assign(consumer, partitions):
41-
nonlocal assign_count
42-
assign_count += 1
43-
assert 1 == len(partitions)
39+
class RebalanceState:
40+
def __init__(self):
41+
self.assign_count = 0
42+
self.revoke_count = 0
43+
self.lost_count = 0
4444

45-
revoke_count = 0
46-
def on_revoke(consumer, partitions):
47-
nonlocal revoke_count
48-
revoke_count += 1
45+
def on_assign(self, consumer, partitions):
46+
self.assign_count += 1
47+
assert 1 == len(partitions)
4948

50-
lost_count = 0
51-
def on_lost(consumer, partitions):
52-
nonlocal lost_count
53-
lost_count += 1
49+
def on_revoke(self, consumer, partitions):
50+
self.revoke_count += 1
51+
52+
def on_lost(self, consumer, partitions):
53+
self.lost_count += 1
54+
55+
reb = RebalanceState()
5456

5557
topic1 = kafka_cluster.create_topic("topic1")
5658
topic2 = kafka_cluster.create_topic("topic2")
@@ -59,26 +61,32 @@ def on_lost(consumer, partitions):
5961

6062
kafka_cluster.seed_topic(topic1, value_source=[b'a'])
6163

62-
consumer.subscribe([topic1], on_assign=on_assign, on_revoke=on_revoke, on_lost=on_lost)
64+
consumer.subscribe([topic1],
65+
on_assign=reb.on_assign,
66+
on_revoke=reb.on_revoke,
67+
on_lost=reb.on_lost)
6368
msg = consumer.poll(10)
64-
assert msg != None
69+
assert msg is not None
6570
assert msg.value() == b'a'
6671

6772
# Subscribe to a second one partition topic, the second assign
6873
# call should be incremental (checked in the handler).
69-
consumer.subscribe([topic1, topic2], on_assign=on_assign, on_revoke=on_revoke, on_lost=on_lost)
74+
consumer.subscribe([topic1, topic2],
75+
on_assign=reb.on_assign,
76+
on_revoke=reb.on_revoke,
77+
on_lost=reb.on_lost)
7078

7179
kafka_cluster.seed_topic(topic2, value_source=[b'b'])
7280
msg2 = consumer.poll(10)
73-
assert msg2 != None
81+
assert msg2 is not None
7482
assert msg2.value() == b'b'
7583

76-
assert 2 == assign_count
77-
assert 0 == lost_count
78-
assert 0 == revoke_count
84+
assert 2 == reb.assign_count
85+
assert 0 == reb.lost_count
86+
assert 0 == reb.revoke_count
7987

8088
msg3 = consumer.poll(1)
81-
assert msg3 == None
89+
assert msg3 is None
8290

8391
# Exceed MaxPollIntervalMs => lost partitions.
8492
time.sleep(8)
@@ -90,11 +98,10 @@ def on_lost(consumer, partitions):
9098

9199
# And poll again to trigger rebalance callbacks
92100
msg4 = consumer.poll(1)
93-
assert msg4 == None
101+
assert msg4 is None
94102

95-
assert 2 == assign_count
96-
assert 1 == lost_count
97-
assert 0 == revoke_count
103+
assert 2 == reb.assign_count
104+
assert 1 == reb.lost_count
105+
assert 0 == reb.revoke_count
98106

99107
consumer.close()
100-

tests/integration/consumer/test_cooperative_rebalance_2.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,36 @@ def test_cooperative_rebalance_2(kafka_cluster):
3535
'enable.auto.commit': 'false',
3636
'auto.offset.reset': 'earliest',
3737
'heartbeat.interval.ms': '2000',
38-
'session.timeout.ms': '6000', # minimum allowed by broker
38+
'session.timeout.ms': '6000', # minimum allowed by broker
3939
'max.poll.interval.ms': '6500'}
4040

41-
assign_count = 0
42-
def on_assign(consumer, partitions):
43-
nonlocal assign_count
44-
assign_count += 1
41+
class RebalanceState:
42+
def __init__(self):
43+
self.assign_count = 0
44+
self.revoke_count = 0
4545

46-
revoke_count = 0
47-
def on_revoke(consumer, partitions):
48-
nonlocal revoke_count
49-
revoke_count += 1
46+
def on_assign(self, consumer, partitions):
47+
self.assign_count += 1
48+
assert 1 == len(partitions)
49+
50+
def on_revoke(self, consumer, partitions):
51+
self.revoke_count += 1
52+
53+
reb = RebalanceState()
5054

5155
topic1 = kafka_cluster.create_topic("topic1")
52-
topic2 = kafka_cluster.create_topic("topic2")
5356

5457
consumer = kafka_cluster.consumer(consumer_conf)
5558

5659
kafka_cluster.seed_topic(topic1, value_source=[b'a'])
5760

58-
consumer.subscribe([topic1], on_assign=on_assign, on_revoke=on_revoke)
61+
consumer.subscribe([topic1],
62+
on_assign=reb.on_assign,
63+
on_revoke=reb.on_revoke)
5964
msg = consumer.poll(10)
60-
assert msg != None
65+
assert msg is not None
6166
assert msg.value() == b'a'
62-
assert assign_count == 1
67+
assert reb.assign_count == 1
6368

6469
# Exceed MaxPollIntervalMs => lost partitions.
6570
time.sleep(8)
@@ -71,8 +76,8 @@ def on_revoke(consumer, partitions):
7176

7277
# The second call should trigger the revoked handler (because a lost
7378
# handler has not been specified).
74-
assert 0 == revoke_count
79+
assert 0 == reb.revoke_count
7580
consumer.poll(1)
76-
assert 1 == revoke_count
81+
assert 1 == reb.revoke_count
7782

7883
consumer.close()

tests/integration/consumer/test_incremental_assign.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_incremental_assign(kafka_cluster):
4040

4141
consumer.incremental_assign([TopicPartition(topic1, 0, OFFSET_BEGINNING)])
4242
msg1 = consumer.poll(10)
43-
assert msg1 != None
43+
assert msg1 is not None
4444
assert 0 == msg1.offset()
4545
assert topic1 == msg1.topic()
4646
assert 0 == msg1.partition()
@@ -54,33 +54,33 @@ def test_incremental_assign(kafka_cluster):
5454

5555
consumer.incremental_assign([TopicPartition(topic2, 0, OFFSET_BEGINNING)])
5656
msg2 = consumer.poll(10)
57-
assert msg2 != None
57+
assert msg2 is not None
5858
assert 0 == msg2.offset()
5959
assert topic2 == msg2.topic()
6060
assert 0 == msg2.partition()
61-
61+
6262
consumer.incremental_unassign([TopicPartition(topic1, 0)])
6363
kafka_cluster.seed_topic(topic1, value_source=[b'aa'])
6464
msg3 = consumer.poll(2)
65-
assert msg3 == None
65+
assert msg3 is None
6666

6767
kafka_cluster.seed_topic(topic2, value_source=[b'aaa'])
6868
msg4 = consumer.poll(10)
69-
assert msg4 != None
69+
assert msg4 is not None
7070
assert 1 == msg4.offset()
7171
assert topic2 == msg4.topic()
7272
assert 0 == msg4.partition()
7373
assert msg4.value() == b'aaa'
7474

7575
consumer.incremental_assign([TopicPartition(topic1, 0)])
7676
msg5 = consumer.poll(10)
77-
assert msg5 != None
77+
assert msg5 is not None
7878
assert 1 == msg5.offset()
7979
assert topic1 == msg5.topic()
8080
assert 0 == msg5.partition()
8181

8282
msg6 = consumer.poll(1)
83-
assert msg6 == None
83+
assert msg6 is None
8484

8585
consumer.incremental_unassign([TopicPartition(topic1, 0)])
8686

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy