pytest-kafka-broker 0.2.0__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/.gitignore +1 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/PKG-INFO +1 -1
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/src/pytest_kafka_broker/__init__.py +9 -1
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/src/pytest_kafka_broker.egg-info/PKG-INFO +1 -1
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/tests/test_kafka.py +19 -11
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/.gitlab-ci.yml +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/.pre-commit-config.yaml +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/.readthedocs.yml +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/README.md +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/docs/Makefile +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/docs/conf.py +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/docs/index.rst +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/docs/make.bat +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/pyproject.toml +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/setup.cfg +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/src/pytest_kafka_broker/py.typed +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/src/pytest_kafka_broker.egg-info/SOURCES.txt +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/src/pytest_kafka_broker.egg-info/dependency_links.txt +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/src/pytest_kafka_broker.egg-info/entry_points.txt +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/src/pytest_kafka_broker.egg-info/requires.txt +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/src/pytest_kafka_broker.egg-info/top_level.txt +0 -0
- {pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/tests/__init__.py +0 -0
|
@@ -12,6 +12,7 @@ import pytest_asyncio
|
|
|
12
12
|
from astropy.config import get_cache_dir_path # type: ignore[import-untyped]
|
|
13
13
|
from astropy.utils.data import get_readable_fileobj # type: ignore[import-untyped]
|
|
14
14
|
from confluent_kafka import Consumer, Producer
|
|
15
|
+
from confluent_kafka.admin import AdminClient
|
|
15
16
|
from confluent_kafka.aio import AIOConsumer, AIOProducer
|
|
16
17
|
from rich.status import Status
|
|
17
18
|
|
|
@@ -87,6 +88,9 @@ class KafkaBrokerContext:
|
|
|
87
88
|
def config(self, config: dict | None = None) -> dict:
|
|
88
89
|
return {**(config or {}), "bootstrap.servers": self.bootstrap_server}
|
|
89
90
|
|
|
91
|
+
def admin(self, config: dict | None = None) -> AdminClient:
|
|
92
|
+
return AdminClient(self.config(config))
|
|
93
|
+
|
|
90
94
|
def producer(self, config: dict | None = None) -> Producer:
|
|
91
95
|
return Producer(self.config(config))
|
|
92
96
|
|
|
@@ -100,6 +104,7 @@ class KafkaBrokerContext:
|
|
|
100
104
|
return AIOConsumer(self.config(config))
|
|
101
105
|
|
|
102
106
|
config.__doc__ = _doc.format("Get the configuration for a Kafka client.")
|
|
107
|
+
admin.__doc__ = _doc.format("Create a Kafka admin client connected to the cluster.")
|
|
103
108
|
producer.__doc__ = _doc.format("Create a Kafka producer connected to the cluster.")
|
|
104
109
|
consumer.__doc__ = _doc.format("Create a Kafka consumer connected to the cluster.")
|
|
105
110
|
aio_producer.__doc__ = _doc.format(
|
|
@@ -181,5 +186,8 @@ async def kafka_broker(
|
|
|
181
186
|
yield KafkaBrokerContext(f"127.0.0.1:{plaintext_port}")
|
|
182
187
|
finally:
|
|
183
188
|
with Status("Stopping Kafka broker"):
|
|
184
|
-
|
|
189
|
+
try:
|
|
190
|
+
process.terminate()
|
|
191
|
+
except ProcessLookupError:
|
|
192
|
+
pass # Process has already terminated
|
|
185
193
|
await exited
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import pytest
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
TOPIC = "topic"
|
|
4
|
+
PAYLOAD = b"hello world"
|
|
5
|
+
GROUP_ID = "group_id"
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
def test_sync(kafka_broker):
|
|
9
9
|
"""Demonstrate using the kafka_broker fixture in an ordinary test."""
|
|
10
10
|
with kafka_broker.producer() as producer:
|
|
11
|
-
producer.produce(
|
|
11
|
+
producer.produce(TOPIC, PAYLOAD)
|
|
12
|
+
|
|
12
13
|
with kafka_broker.consumer(
|
|
13
|
-
{"group.id":
|
|
14
|
+
{"group.id": GROUP_ID, "auto.offset.reset": "earliest"}
|
|
14
15
|
) as consumer:
|
|
15
|
-
consumer.subscribe([
|
|
16
|
+
consumer.subscribe([TOPIC])
|
|
16
17
|
(message,) = consumer.consume()
|
|
17
|
-
assert message.value() ==
|
|
18
|
+
assert message.value() == PAYLOAD
|
|
19
|
+
|
|
20
|
+
with kafka_broker.admin() as admin:
|
|
21
|
+
assert TOPIC in admin.list_topics().topics
|
|
18
22
|
|
|
19
23
|
|
|
20
24
|
@pytest.mark.asyncio
|
|
@@ -22,17 +26,21 @@ async def test_async(kafka_broker):
|
|
|
22
26
|
"""Demonstrate using the kafka_broker fixture in an async test."""
|
|
23
27
|
producer = kafka_broker.aio_producer()
|
|
24
28
|
try:
|
|
25
|
-
await producer.produce(
|
|
29
|
+
await producer.produce(TOPIC, PAYLOAD)
|
|
26
30
|
finally:
|
|
27
31
|
# FIXME: use async context manager; see https://github.com/confluentinc/confluent-kafka-python/pull/2180
|
|
28
32
|
await producer.close()
|
|
29
33
|
consumer = kafka_broker.aio_consumer(
|
|
30
|
-
{"group.id":
|
|
34
|
+
{"group.id": GROUP_ID, "auto.offset.reset": "earliest"}
|
|
31
35
|
)
|
|
36
|
+
|
|
32
37
|
try:
|
|
33
|
-
await consumer.subscribe([
|
|
38
|
+
await consumer.subscribe([TOPIC])
|
|
34
39
|
(message,) = await consumer.consume()
|
|
35
40
|
finally:
|
|
36
41
|
# FIXME: use async context manager; see https://github.com/confluentinc/confluent-kafka-python/pull/2180
|
|
37
42
|
await consumer.close()
|
|
38
|
-
assert message.value() ==
|
|
43
|
+
assert message.value() == PAYLOAD
|
|
44
|
+
|
|
45
|
+
with kafka_broker.admin() as admin:
|
|
46
|
+
assert TOPIC in admin.list_topics().topics
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_kafka_broker-0.2.0 → pytest_kafka_broker-0.3.1}/src/pytest_kafka_broker.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|