summaryrefslogtreecommitdiff
path: root/test/test_util.py
diff options
context:
space:
mode:
authorDana Powers <dana.powers@rd.io>2014-09-07 18:52:05 -0700
committerDana Powers <dana.powers@rd.io>2014-09-07 19:09:32 -0700
commit715425c639a476139065689afde3d255a07d6f96 (patch)
tree0ef2cd875c97c8ca867d89328d6fd5fec7dfcbe8 /test/test_util.py
parenta99384f4c601d127ab1c4fe5b272ea5c07fd695d (diff)
parentbe23042ecd9ab330886745ccc9ec9e3a0039836f (diff)
downloadkafka-python-715425c639a476139065689afde3d255a07d6f96.tar.gz
Merge pull request #227 from wizzat-feature/py3
Python 3 Support Conflicts: kafka/producer.py test/test_client.py test/test_client_integration.py test/test_codec.py test/test_consumer.py test/test_consumer_integration.py test/test_failover_integration.py test/test_producer.py test/test_producer_integration.py test/test_protocol.py test/test_util.py
Diffstat (limited to 'test/test_util.py')
-rw-r--r--test/test_util.py61
1 files changed, 34 insertions, 27 deletions
diff --git a/test/test_util.py b/test/test_util.py
index dbc3fe6..6a8f45b 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -1,21 +1,22 @@
# -*- coding: utf-8 -*-
import struct
-import unittest2
+import six
+from . import unittest
-import kafka.util
import kafka.common
+import kafka.util
-class UtilTest(unittest2.TestCase):
- @unittest2.skip("Unwritten")
+class UtilTest(unittest.TestCase):
+ @unittest.skip("Unwritten")
def test_relative_unpack(self):
pass
def test_write_int_string(self):
self.assertEqual(
- kafka.util.write_int_string('some string'),
- '\x00\x00\x00\x0bsome string'
+ kafka.util.write_int_string(b'some string'),
+ b'\x00\x00\x00\x0bsome string'
)
def test_write_int_string__unicode(self):
@@ -23,34 +24,37 @@ class UtilTest(unittest2.TestCase):
kafka.util.write_int_string(u'unicode')
#: :type: TypeError
te = cm.exception
- self.assertIn('unicode', te.message)
- self.assertIn('to be str', te.message)
+ if six.PY2:
+ self.assertIn('unicode', str(te))
+ else:
+ self.assertIn('str', str(te))
+ self.assertIn('to be bytes', str(te))
def test_write_int_string__empty(self):
self.assertEqual(
- kafka.util.write_int_string(''),
- '\x00\x00\x00\x00'
+ kafka.util.write_int_string(b''),
+ b'\x00\x00\x00\x00'
)
def test_write_int_string__null(self):
self.assertEqual(
kafka.util.write_int_string(None),
- '\xff\xff\xff\xff'
+ b'\xff\xff\xff\xff'
)
def test_read_int_string(self):
- self.assertEqual(kafka.util.read_int_string('\xff\xff\xff\xff', 0), (None, 4))
- self.assertEqual(kafka.util.read_int_string('\x00\x00\x00\x00', 0), ('', 4))
- self.assertEqual(kafka.util.read_int_string('\x00\x00\x00\x0bsome string', 0), ('some string', 15))
+ self.assertEqual(kafka.util.read_int_string(b'\xff\xff\xff\xff', 0), (None, 4))
+ self.assertEqual(kafka.util.read_int_string(b'\x00\x00\x00\x00', 0), (b'', 4))
+ self.assertEqual(kafka.util.read_int_string(b'\x00\x00\x00\x0bsome string', 0), (b'some string', 15))
def test_read_int_string__insufficient_data(self):
with self.assertRaises(kafka.common.BufferUnderflowError):
- kafka.util.read_int_string('\x00\x00\x00\x021', 0)
+ kafka.util.read_int_string(b'\x00\x00\x00\x021', 0)
def test_write_short_string(self):
self.assertEqual(
- kafka.util.write_short_string('some string'),
- '\x00\x0bsome string'
+ kafka.util.write_short_string(b'some string'),
+ b'\x00\x0bsome string'
)
def test_write_short_string__unicode(self):
@@ -58,29 +62,32 @@ class UtilTest(unittest2.TestCase):
kafka.util.write_short_string(u'hello')
#: :type: TypeError
te = cm.exception
- self.assertIn('unicode', te.message)
- self.assertIn('to be str', te.message)
+ if six.PY2:
+ self.assertIn('unicode', str(te))
+ else:
+ self.assertIn('str', str(te))
+ self.assertIn('to be bytes', str(te))
def test_write_short_string__empty(self):
self.assertEqual(
- kafka.util.write_short_string(''),
- '\x00\x00'
+ kafka.util.write_short_string(b''),
+ b'\x00\x00'
)
def test_write_short_string__null(self):
self.assertEqual(
kafka.util.write_short_string(None),
- '\xff\xff'
+ b'\xff\xff'
)
def test_write_short_string__too_long(self):
with self.assertRaises(struct.error):
- kafka.util.write_short_string(' ' * 33000)
+ kafka.util.write_short_string(b' ' * 33000)
def test_read_short_string(self):
- self.assertEqual(kafka.util.read_short_string('\xff\xff', 0), (None, 2))
- self.assertEqual(kafka.util.read_short_string('\x00\x00', 0), ('', 2))
- self.assertEqual(kafka.util.read_short_string('\x00\x0bsome string', 0), ('some string', 13))
+ self.assertEqual(kafka.util.read_short_string(b'\xff\xff', 0), (None, 2))
+ self.assertEqual(kafka.util.read_short_string(b'\x00\x00', 0), (b'', 2))
+ self.assertEqual(kafka.util.read_short_string(b'\x00\x0bsome string', 0), (b'some string', 13))
def test_read_int_string__insufficient_data2(self):
with self.assertRaises(kafka.common.BufferUnderflowError):
@@ -88,7 +95,7 @@ class UtilTest(unittest2.TestCase):
def test_relative_unpack2(self):
self.assertEqual(
- kafka.util.relative_unpack('>hh', '\x00\x01\x00\x00\x02', 0),
+ kafka.util.relative_unpack('>hh', b'\x00\x01\x00\x00\x02', 0),
((1, 0), 4)
)