diff options
author | Dana Powers <dana.powers@rd.io> | 2015-06-04 22:10:21 -0700 |
---|---|---|
committer | Dana Powers <dana.powers@rd.io> | 2015-06-06 16:22:27 -0700 |
commit | 207499b26d5ce6c7a72771250b8e4365944aa1bd (patch) | |
tree | daa38905d6a547ca9e4679253b4fc3c664199866 | |
parent | 868115c703afc4403adc8d9481bf31d2c15064dd (diff) | |
download | kafka-python-207499b26d5ce6c7a72771250b8e4365944aa1bd.tar.gz |
random_string helper should return str not bytes
-rw-r--r-- | test/test_codec.py | 12 | ||||
-rw-r--r-- | test/test_consumer_integration.py | 2 | ||||
-rw-r--r-- | test/test_failover_integration.py | 14 | ||||
-rw-r--r-- | test/testutil.py | 5 |
4 files changed, 16 insertions, 17 deletions
diff --git a/test/test_codec.py b/test/test_codec.py index 2d7670a..3416fdb 100644 --- a/test/test_codec.py +++ b/test/test_codec.py @@ -13,16 +13,16 @@ from test.testutil import random_string class TestCodec(unittest.TestCase): def test_gzip(self): for i in xrange(1000): - s1 = random_string(100) - s2 = gzip_decode(gzip_encode(s1)) - self.assertEqual(s1, s2) + b1 = random_string(100).encode('utf-8') + b2 = gzip_decode(gzip_encode(b1)) + self.assertEqual(b1, b2) @unittest.skipUnless(has_snappy(), "Snappy not available") def test_snappy(self): for i in xrange(1000): - s1 = random_string(100) - s2 = snappy_decode(snappy_encode(s1)) - self.assertEqual(s1, s2) + b1 = random_string(100).encode('utf-8') + b2 = snappy_decode(snappy_encode(b1)) + self.assertEqual(b1, b2) @unittest.skipUnless(has_snappy(), "Snappy not available") def test_snappy_detect_xerial(self): diff --git a/test/test_consumer_integration.py b/test/test_consumer_integration.py index ddb54a7..3825f94 100644 --- a/test/test_consumer_integration.py +++ b/test/test_consumer_integration.py @@ -475,7 +475,7 @@ class TestConsumerIntegration(KafkaIntegrationTestCase): @kafka_versions("0.8.1", "0.8.1.1", "0.8.2.0") def test_kafka_consumer__offset_commit_resume(self): - GROUP_ID = random_string(10) + GROUP_ID = random_string(10).encode('utf-8') self.send_messages(0, range(0, 100)) self.send_messages(1, range(100, 200)) diff --git a/test/test_failover_integration.py b/test/test_failover_integration.py index 3be0189..11e255d 100644 --- a/test/test_failover_integration.py +++ b/test/test_failover_integration.py @@ -133,8 +133,8 @@ class TestFailover(KafkaIntegrationTestCase): # Send 10 random messages for _ in range(10): - key = random_string(3) - msg = random_string(10) + key = random_string(3).encode('utf-8') + msg = random_string(10).encode('utf-8') producer.send_messages(topic, key, msg) # kill leader for partition 0 @@ -145,8 +145,8 @@ class TestFailover(KafkaIntegrationTestCase): timeout = 60 while not recovered and (time.time() - started) < timeout: try: - key = random_string(3) - msg = random_string(10) + key = random_string(3).encode('utf-8') + msg = random_string(10).encode('utf-8') producer.send_messages(topic, key, msg) if producer.partitioners[kafka_bytestring(topic)].partition(key) == 0: recovered = True @@ -159,15 +159,15 @@ class TestFailover(KafkaIntegrationTestCase): # send some more messages just to make sure no more exceptions for _ in range(10): - key = random_string(3) - msg = random_string(10) + key = random_string(3).encode('utf-8') + msg = random_string(10).encode('utf-8') producer.send_messages(topic, key, msg) def _send_random_messages(self, producer, topic, partition, n): for j in range(n): logging.debug('_send_random_message to %s:%d -- try %d', topic, partition, j) - resp = producer.send_messages(topic, partition, random_string(10)) + resp = producer.send_messages(topic, partition, random_string(10).encode('utf-8')) if len(resp) > 0: self.assertEqual(resp[0].error, 0) logging.debug('_send_random_message to %s:%d -- try %d success', topic, partition, j) diff --git a/test/testutil.py b/test/testutil.py index e6947b4..1f1a1df 100644 --- a/test/testutil.py +++ b/test/testutil.py @@ -23,8 +23,7 @@ __all__ = [ ] def random_string(l): - s = "".join(random.choice(string.ascii_letters) for i in xrange(l)) - return s.encode('utf-8') + return "".join(random.choice(string.ascii_letters) for i in xrange(l)) def kafka_versions(*versions): def kafka_versions(func): @@ -60,7 +59,7 @@ class KafkaIntegrationTestCase(unittest.TestCase): return if not self.topic: - topic = "%s-%s" % (self.id()[self.id().rindex(".") + 1:], random_string(10).decode('utf-8')) + topic = "%s-%s" % (self.id()[self.id().rindex(".") + 1:], random_string(10)) self.topic = topic self.bytes_topic = topic.encode('utf-8') |