Skip to content

Commit 207499b

Browse files
author
Dana Powers
committed
random_string helper should return str not bytes
1 parent 868115c commit 207499b

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

test/test_codec.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
class TestCodec(unittest.TestCase):
1414
def test_gzip(self):
1515
for i in xrange(1000):
16-
s1 = random_string(100)
17-
s2 = gzip_decode(gzip_encode(s1))
18-
self.assertEqual(s1, s2)
16+
b1 = random_string(100).encode('utf-8')
17+
b2 = gzip_decode(gzip_encode(b1))
18+
self.assertEqual(b1, b2)
1919

2020
@unittest.skipUnless(has_snappy(), "Snappy not available")
2121
def test_snappy(self):
2222
for i in xrange(1000):
23-
s1 = random_string(100)
24-
s2 = snappy_decode(snappy_encode(s1))
25-
self.assertEqual(s1, s2)
23+
b1 = random_string(100).encode('utf-8')
24+
b2 = snappy_decode(snappy_encode(b1))
25+
self.assertEqual(b1, b2)
2626

2727
@unittest.skipUnless(has_snappy(), "Snappy not available")
2828
def test_snappy_detect_xerial(self):

test/test_consumer_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def test_kafka_consumer__blocking(self):
475475

476476
@kafka_versions("0.8.1", "0.8.1.1", "0.8.2.0")
477477
def test_kafka_consumer__offset_commit_resume(self):
478-
GROUP_ID = random_string(10)
478+
GROUP_ID = random_string(10).encode('utf-8')
479479

480480
self.send_messages(0, range(0, 100))
481481
self.send_messages(1, range(100, 200))

test/test_failover_integration.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def test_switch_leader_keyed_producer(self):
133133

134134
# Send 10 random messages
135135
for _ in range(10):
136-
key = random_string(3)
137-
msg = random_string(10)
136+
key = random_string(3).encode('utf-8')
137+
msg = random_string(10).encode('utf-8')
138138
producer.send_messages(topic, key, msg)
139139

140140
# kill leader for partition 0
@@ -145,8 +145,8 @@ def test_switch_leader_keyed_producer(self):
145145
timeout = 60
146146
while not recovered and (time.time() - started) < timeout:
147147
try:
148-
key = random_string(3)
149-
msg = random_string(10)
148+
key = random_string(3).encode('utf-8')
149+
msg = random_string(10).encode('utf-8')
150150
producer.send_messages(topic, key, msg)
151151
if producer.partitioners[kafka_bytestring(topic)].partition(key) == 0:
152152
recovered = True
@@ -159,15 +159,15 @@ def test_switch_leader_keyed_producer(self):
159159

160160
# send some more messages just to make sure no more exceptions
161161
for _ in range(10):
162-
key = random_string(3)
163-
msg = random_string(10)
162+
key = random_string(3).encode('utf-8')
163+
msg = random_string(10).encode('utf-8')
164164
producer.send_messages(topic, key, msg)
165165

166166

167167
def _send_random_messages(self, producer, topic, partition, n):
168168
for j in range(n):
169169
logging.debug('_send_random_message to %s:%d -- try %d', topic, partition, j)
170-
resp = producer.send_messages(topic, partition, random_string(10))
170+
resp = producer.send_messages(topic, partition, random_string(10).encode('utf-8'))
171171
if len(resp) > 0:
172172
self.assertEqual(resp[0].error, 0)
173173
logging.debug('_send_random_message to %s:%d -- try %d success', topic, partition, j)

test/testutil.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
]
2424

2525
def random_string(l):
26-
s = "".join(random.choice(string.ascii_letters) for i in xrange(l))
27-
return s.encode('utf-8')
26+
return "".join(random.choice(string.ascii_letters) for i in xrange(l))
2827

2928
def kafka_versions(*versions):
3029
def kafka_versions(func):
@@ -60,7 +59,7 @@ def setUp(self):
6059
return
6160

6261
if not self.topic:
63-
topic = "%s-%s" % (self.id()[self.id().rindex(".") + 1:], random_string(10).decode('utf-8'))
62+
topic = "%s-%s" % (self.id()[self.id().rindex(".") + 1:], random_string(10))
6463
self.topic = topic
6564
self.bytes_topic = topic.encode('utf-8')
6665

0 commit comments

Comments
 (0)