Use base unittest or unittest2 depending on python version
This commit is contained in:
committed by
Mark Roberts
parent
eddd1436c2
commit
83af5102e9
7
setup.py
7
setup.py
@@ -22,11 +22,16 @@ class Tox(Command):
|
|||||||
sys.exit(tox.cmdline([]))
|
sys.exit(tox.cmdline([]))
|
||||||
|
|
||||||
|
|
||||||
|
test_require = ['tox', 'mock']
|
||||||
|
if sys.version_info < (2, 7):
|
||||||
|
test_require.append('unittest2')
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="kafka-python",
|
name="kafka-python",
|
||||||
version=__version__,
|
version=__version__,
|
||||||
|
|
||||||
tests_require=["tox", "mock", "unittest2"],
|
tests_require=test_require,
|
||||||
cmdclass={"test": Tox},
|
cmdclass={"test": Tox},
|
||||||
|
|
||||||
packages=["kafka"],
|
packages=["kafka"],
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.version_info < (2, 7):
|
||||||
|
import unittest2 as unittest
|
||||||
|
else:
|
||||||
|
import unittest
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import unittest2
|
from . import unittest
|
||||||
|
|
||||||
from mock import MagicMock, patch
|
from mock import MagicMock, patch
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ from kafka.common import (
|
|||||||
)
|
)
|
||||||
from kafka.protocol import create_message
|
from kafka.protocol import create_message
|
||||||
|
|
||||||
class TestKafkaClient(unittest2.TestCase):
|
class TestKafkaClient(unittest.TestCase):
|
||||||
def test_init_with_list(self):
|
def test_init_with_list(self):
|
||||||
with patch.object(KafkaClient, 'load_metadata_for_topics'):
|
with patch.object(KafkaClient, 'load_metadata_for_topics'):
|
||||||
client = KafkaClient(hosts=['kafka01:9092', 'kafka02:9092', 'kafka03:9092'])
|
client = KafkaClient(hosts=['kafka01:9092', 'kafka02:9092', 'kafka03:9092'])
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import unittest2
|
from . import unittest
|
||||||
|
|
||||||
import kafka
|
import kafka
|
||||||
from kafka.common import *
|
from kafka.common import *
|
||||||
@@ -24,7 +24,7 @@ class TestKafkaClientIntegration(KafkaIntegrationTestCase):
|
|||||||
cls.server.close()
|
cls.server.close()
|
||||||
cls.zk.close()
|
cls.zk.close()
|
||||||
|
|
||||||
@unittest2.skip("This doesn't appear to work on Linux?")
|
@unittest.skip("This doesn't appear to work on Linux?")
|
||||||
def test_timeout(self):
|
def test_timeout(self):
|
||||||
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
server_port = get_open_port()
|
server_port = get_open_port()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import struct
|
import struct
|
||||||
import unittest2
|
from . import unittest
|
||||||
|
|
||||||
from kafka.codec import (
|
from kafka.codec import (
|
||||||
has_snappy, gzip_encode, gzip_decode,
|
has_snappy, gzip_encode, gzip_decode,
|
||||||
@@ -10,21 +10,21 @@ from kafka.protocol import (
|
|||||||
)
|
)
|
||||||
from testutil import *
|
from testutil import *
|
||||||
|
|
||||||
class TestCodec(unittest2.TestCase):
|
class TestCodec(unittest.TestCase):
|
||||||
def test_gzip(self):
|
def test_gzip(self):
|
||||||
for i in xrange(1000):
|
for i in xrange(1000):
|
||||||
s1 = random_string(100)
|
s1 = random_string(100)
|
||||||
s2 = gzip_decode(gzip_encode(s1))
|
s2 = gzip_decode(gzip_encode(s1))
|
||||||
self.assertEquals(s1, s2)
|
self.assertEquals(s1, s2)
|
||||||
|
|
||||||
@unittest2.skipUnless(has_snappy(), "Snappy not available")
|
@unittest.skipUnless(has_snappy(), "Snappy not available")
|
||||||
def test_snappy(self):
|
def test_snappy(self):
|
||||||
for i in xrange(1000):
|
for i in xrange(1000):
|
||||||
s1 = random_string(100)
|
s1 = random_string(100)
|
||||||
s2 = snappy_decode(snappy_encode(s1))
|
s2 = snappy_decode(snappy_encode(s1))
|
||||||
self.assertEquals(s1, s2)
|
self.assertEquals(s1, s2)
|
||||||
|
|
||||||
@unittest2.skipUnless(has_snappy(), "Snappy not available")
|
@unittest.skipUnless(has_snappy(), "Snappy not available")
|
||||||
def test_snappy_detect_xerial(self):
|
def test_snappy_detect_xerial(self):
|
||||||
import kafka as kafka1
|
import kafka as kafka1
|
||||||
_detect_xerial_stream = kafka1.codec._detect_xerial_stream
|
_detect_xerial_stream = kafka1.codec._detect_xerial_stream
|
||||||
@@ -41,7 +41,7 @@ class TestCodec(unittest2.TestCase):
|
|||||||
self.assertFalse(_detect_xerial_stream(random_snappy))
|
self.assertFalse(_detect_xerial_stream(random_snappy))
|
||||||
self.assertFalse(_detect_xerial_stream(short_data))
|
self.assertFalse(_detect_xerial_stream(short_data))
|
||||||
|
|
||||||
@unittest2.skipUnless(has_snappy(), "Snappy not available")
|
@unittest.skipUnless(has_snappy(), "Snappy not available")
|
||||||
def test_snappy_decode_xerial(self):
|
def test_snappy_decode_xerial(self):
|
||||||
header = b'\x82SNAPPY\x00\x00\x00\x00\x01\x00\x00\x00\x01'
|
header = b'\x82SNAPPY\x00\x00\x00\x00\x01\x00\x00\x00\x01'
|
||||||
random_snappy = snappy_encode('SNAPPY' * 50)
|
random_snappy = snappy_encode('SNAPPY' * 50)
|
||||||
@@ -55,7 +55,7 @@ class TestCodec(unittest2.TestCase):
|
|||||||
|
|
||||||
self.assertEquals(snappy_decode(to_test), ('SNAPPY' * 50) + ('XERIAL' * 50))
|
self.assertEquals(snappy_decode(to_test), ('SNAPPY' * 50) + ('XERIAL' * 50))
|
||||||
|
|
||||||
@unittest2.skipUnless(has_snappy(), "Snappy not available")
|
@unittest.skipUnless(has_snappy(), "Snappy not available")
|
||||||
def test_snappy_encode_xerial(self):
|
def test_snappy_encode_xerial(self):
|
||||||
to_ensure = b'\x82SNAPPY\x00\x00\x00\x00\x01\x00\x00\x00\x01' + \
|
to_ensure = b'\x82SNAPPY\x00\x00\x00\x00\x01\x00\x00\x00\x01' + \
|
||||||
'\x00\x00\x00\x18' + \
|
'\x00\x00\x00\x18' + \
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import socket
|
|||||||
import struct
|
import struct
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import unittest2
|
from . import unittest
|
||||||
|
|
||||||
from kafka.common import *
|
from kafka.common import *
|
||||||
from kafka.conn import *
|
from kafka.conn import *
|
||||||
|
|
||||||
class ConnTest(unittest2.TestCase):
|
class ConnTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.config = {
|
self.config = {
|
||||||
'host': 'localhost',
|
'host': 'localhost',
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import struct
|
import struct
|
||||||
import unittest2
|
from . import unittest
|
||||||
|
|
||||||
from mock import MagicMock, patch
|
from mock import MagicMock, patch
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ from kafka.protocol import (
|
|||||||
create_message, KafkaProtocol
|
create_message, KafkaProtocol
|
||||||
)
|
)
|
||||||
|
|
||||||
class TestKafkaConsumer(unittest2.TestCase):
|
class TestKafkaConsumer(unittest.TestCase):
|
||||||
def test_non_integer_partitions(self):
|
def test_non_integer_partitions(self):
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
consumer = SimpleConsumer(MagicMock(), 'group', 'topic', partitions = [ '0' ])
|
consumer = SimpleConsumer(MagicMock(), 'group', 'topic', partitions = [ '0' ])
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import unittest2
|
from . import unittest
|
||||||
|
|
||||||
from kafka import * # noqa
|
from kafka import * # noqa
|
||||||
from kafka.common import * # noqa
|
from kafka.common import * # noqa
|
||||||
@@ -82,7 +82,7 @@ class TestFailover(KafkaIntegrationTestCase):
|
|||||||
|
|
||||||
|
|
||||||
#@kafka_versions("all")
|
#@kafka_versions("all")
|
||||||
@unittest2.skip("async producer does not support reliable failover yet")
|
@unittest.skip("async producer does not support reliable failover yet")
|
||||||
def test_switch_leader_async(self):
|
def test_switch_leader_async(self):
|
||||||
key, topic, partition = random_string(5), self.topic, 0
|
key, topic, partition = random_string(5), self.topic, 0
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import unittest2
|
from . import unittest
|
||||||
|
|
||||||
class TestPackage(unittest2.TestCase):
|
class TestPackage(unittest.TestCase):
|
||||||
def test_top_level_namespace(self):
|
def test_top_level_namespace(self):
|
||||||
import kafka as kafka1
|
import kafka as kafka1
|
||||||
self.assertEquals(kafka1.KafkaClient.__name__, "KafkaClient")
|
self.assertEquals(kafka1.KafkaClient.__name__, "KafkaClient")
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import struct
|
import struct
|
||||||
import unittest2
|
from . import unittest
|
||||||
|
|
||||||
from mock import MagicMock, patch
|
from mock import MagicMock, patch
|
||||||
|
|
||||||
from kafka import KafkaClient
|
from kafka import KafkaClient
|
||||||
from kafka.producer import Producer
|
from kafka.producer import Producer
|
||||||
|
|
||||||
class TestKafkaProducer(unittest2.TestCase):
|
class TestKafkaProducer(unittest.TestCase):
|
||||||
def test_producer_message_types(self):
|
def test_producer_message_types(self):
|
||||||
|
|
||||||
producer = Producer(MagicMock())
|
producer = Producer(MagicMock())
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
import struct
|
import struct
|
||||||
import unittest2
|
from . import unittest
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from mock import sentinel
|
from mock import sentinel
|
||||||
@@ -27,7 +27,7 @@ from kafka.protocol import (
|
|||||||
create_message_set
|
create_message_set
|
||||||
)
|
)
|
||||||
|
|
||||||
class TestProtocol(unittest2.TestCase):
|
class TestProtocol(unittest.TestCase):
|
||||||
def test_create_message(self):
|
def test_create_message(self):
|
||||||
payload = "test"
|
payload = "test"
|
||||||
key = "key"
|
key = "key"
|
||||||
@@ -65,7 +65,7 @@ class TestProtocol(unittest2.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(decoded, expect)
|
self.assertEqual(decoded, expect)
|
||||||
|
|
||||||
@unittest2.skipUnless(has_snappy(), "Snappy not available")
|
@unittest.skipUnless(has_snappy(), "Snappy not available")
|
||||||
def test_create_snappy(self):
|
def test_create_snappy(self):
|
||||||
payloads = ["v1", "v2"]
|
payloads = ["v1", "v2"]
|
||||||
msg = create_snappy_message(payloads)
|
msg = create_snappy_message(payloads)
|
||||||
@@ -222,7 +222,7 @@ class TestProtocol(unittest2.TestCase):
|
|||||||
self.assertEqual(returned_offset2, 0)
|
self.assertEqual(returned_offset2, 0)
|
||||||
self.assertEqual(decoded_message2, create_message("v2"))
|
self.assertEqual(decoded_message2, create_message("v2"))
|
||||||
|
|
||||||
@unittest2.skipUnless(has_snappy(), "Snappy not available")
|
@unittest.skipUnless(has_snappy(), "Snappy not available")
|
||||||
def test_decode_message_snappy(self):
|
def test_decode_message_snappy(self):
|
||||||
snappy_encoded = ('\xec\x80\xa1\x95\x00\x02\xff\xff\xff\xff\x00\x00'
|
snappy_encoded = ('\xec\x80\xa1\x95\x00\x02\xff\xff\xff\xff\x00\x00'
|
||||||
'\x00,8\x00\x00\x19\x01@\x10L\x9f[\xc2\x00\x00\xff'
|
'\x00,8\x00\x00\x19\x01@\x10L\x9f[\xc2\x00\x00\xff'
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import struct
|
import struct
|
||||||
import unittest2
|
|
||||||
import kafka.util
|
import kafka.util
|
||||||
import kafka.common
|
import kafka.common
|
||||||
|
|
||||||
|
from . import unittest
|
||||||
|
|
||||||
class UtilTest(unittest2.TestCase):
|
|
||||||
@unittest2.skip("Unwritten")
|
class UtilTest(unittest.TestCase):
|
||||||
|
@unittest.skip("Unwritten")
|
||||||
def test_relative_unpack(self):
|
def test_relative_unpack(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import random
|
|||||||
import socket
|
import socket
|
||||||
import string
|
import string
|
||||||
import time
|
import time
|
||||||
import unittest2
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from . import unittest
|
||||||
|
|
||||||
from kafka.common import OffsetRequest
|
from kafka.common import OffsetRequest
|
||||||
from kafka import KafkaClient
|
from kafka import KafkaClient
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ def get_open_port():
|
|||||||
sock.close()
|
sock.close()
|
||||||
return port
|
return port
|
||||||
|
|
||||||
class KafkaIntegrationTestCase(unittest2.TestCase):
|
class KafkaIntegrationTestCase(unittest.TestCase):
|
||||||
create_client = True
|
create_client = True
|
||||||
topic = None
|
topic = None
|
||||||
server = None
|
server = None
|
||||||
|
|||||||
Reference in New Issue
Block a user