-
Notifications
You must be signed in to change notification settings - Fork 951
Expand file tree
/
Copy pathtest_partitioners.py
More file actions
36 lines (27 loc) · 1.08 KB
/
test_partitioners.py
File metadata and controls
36 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Unit tests for partitioner functions.
"""
import pytest
from confluent_kafka import consistent, fnv1a, murmur2
class TestPartitioners:
def test_deterministic(self):
"""Test that deterministic partitioners produce the same output for the same input."""
key = b"test_key"
partition_count = 10
# Same input should always produce same output
assert murmur2(key, partition_count) == murmur2(key, partition_count)
assert consistent(key, partition_count) == consistent(key, partition_count)
assert fnv1a(key, partition_count) == fnv1a(key, partition_count)
def test_input_validation(self):
"""Test input validation logic."""
# Invalid partition_count
with pytest.raises(ValueError, match="partition_count must be > 0"):
murmur2(b"key", 0)
# Invalid key type
with pytest.raises(TypeError):
murmur2("string_key", 10)
# Invalid partition_count type
with pytest.raises(TypeError):
murmur2(b"key", "10")