File: test_subscription_state.py

package info (click to toggle)
python-kafka 2.0.2-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,740 kB
  • sloc: python: 20,457; makefile: 210; sh: 76
file content (25 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (4)
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
# pylint: skip-file
from __future__ import absolute_import

import pytest

from kafka.consumer.subscription_state import SubscriptionState

@pytest.mark.parametrize(('topic_name', 'expectation'), [
    (0, pytest.raises(TypeError)),
    (None, pytest.raises(TypeError)),
    ('', pytest.raises(ValueError)),
    ('.', pytest.raises(ValueError)),
    ('..', pytest.raises(ValueError)),
    ('a' * 250, pytest.raises(ValueError)),
    ('abc/123', pytest.raises(ValueError)),
    ('/abc/123', pytest.raises(ValueError)),
    ('/abc123', pytest.raises(ValueError)),
    ('name with space', pytest.raises(ValueError)),
    ('name*with*stars', pytest.raises(ValueError)),
    ('name+with+plus', pytest.raises(ValueError)),
])
def test_topic_name_validation(topic_name, expectation):
    state = SubscriptionState()
    with expectation:
        state._ensure_valid_topic_name(topic_name)