Skip to content

Commit 1945ad1

Browse files
committed
Minor aesthetic cleanup of partitioner tests
1 parent 2b67493 commit 1945ad1

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

test/test_partitioner.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from __future__ import absolute_import
22

3+
import pytest
4+
35
from kafka.partitioner import DefaultPartitioner, Murmur2Partitioner, RoundRobinPartitioner
46
from kafka.partitioner.hashed import murmur2
57

68

79
def test_default_partitioner():
810
partitioner = DefaultPartitioner()
9-
all_partitions = list(range(100))
10-
available = all_partitions
11+
all_partitions = available = list(range(100))
1112
# partitioner should return the same partition for the same key
1213
p1 = partitioner(b'foo', all_partitions, available)
1314
p2 = partitioner(b'foo', all_partitions, available)
@@ -23,8 +24,7 @@ def test_default_partitioner():
2324

2425
def test_roundrobin_partitioner():
2526
partitioner = RoundRobinPartitioner()
26-
all_partitions = list(range(100))
27-
available = all_partitions
27+
all_partitions = available = list(range(100))
2828
# partitioner should cycle between partitions
2929
i = 0
3030
max_partition = all_partitions[len(all_partitions) - 1]
@@ -53,15 +53,14 @@ def test_roundrobin_partitioner():
5353
i += 1
5454

5555

56-
def test_murmur2_java_compatibility():
56+
@pytest.mark.parametrize("bytes_payload,partition_number", [
57+
(b'', 681), (b'a', 524), (b'ab', 434), (b'abc', 107), (b'123456789', 566),
58+
(b'\x00 ', 742)
59+
])
60+
def test_murmur2_java_compatibility(bytes_payload, partition_number):
5761
p = Murmur2Partitioner(range(1000))
5862
# compare with output from Kafka's org.apache.kafka.clients.producer.Partitioner
59-
assert p.partition(b'') == 681
60-
assert p.partition(b'a') == 524
61-
assert p.partition(b'ab') == 434
62-
assert p.partition(b'abc') == 107
63-
assert p.partition(b'123456789') == 566
64-
assert p.partition(b'\x00 ') == 742
63+
assert p.partition(bytes_payload) == partition_number
6564

6665

6766
def test_murmur2_not_ascii():

0 commit comments

Comments
 (0)