pytest-kafka-broker 0.3.1__tar.gz → 0.4.0__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.
Files changed (22) hide show
  1. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/.gitlab-ci.yml +1 -0
  2. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/PKG-INFO +1 -1
  3. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/pyproject.toml +7 -0
  4. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/src/pytest_kafka_broker/__init__.py +35 -3
  5. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/src/pytest_kafka_broker.egg-info/PKG-INFO +1 -1
  6. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/.gitignore +0 -0
  7. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/.pre-commit-config.yaml +0 -0
  8. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/.readthedocs.yml +0 -0
  9. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/README.md +0 -0
  10. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/docs/Makefile +0 -0
  11. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/docs/conf.py +0 -0
  12. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/docs/index.rst +0 -0
  13. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/docs/make.bat +0 -0
  14. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/setup.cfg +0 -0
  15. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/src/pytest_kafka_broker/py.typed +0 -0
  16. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/src/pytest_kafka_broker.egg-info/SOURCES.txt +0 -0
  17. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/src/pytest_kafka_broker.egg-info/dependency_links.txt +0 -0
  18. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/src/pytest_kafka_broker.egg-info/entry_points.txt +0 -0
  19. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/src/pytest_kafka_broker.egg-info/requires.txt +0 -0
  20. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/src/pytest_kafka_broker.egg-info/top_level.txt +0 -0
  21. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/tests/__init__.py +0 -0
  22. {pytest_kafka_broker-0.3.1 → pytest_kafka_broker-0.4.0}/tests/test_kafka.py +0 -0
@@ -7,6 +7,7 @@ include:
7
7
  - "3.12"
8
8
  - "3.13"
9
9
  - "3.14"
10
+ pytest_options: --cov=pytest_kafka_broker --cov=tests
10
11
  - component: git.ligo.org/computing/gitlab/components/python/type-checking@2.3.2
11
12
  inputs:
12
13
  fail_on_findings: true
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-kafka-broker
3
- Version: 0.3.1
3
+ Version: 0.4.0
4
4
  Summary: Pytest plugin to run a single-broker Kafka cluster
5
5
  Author-email: Leo Singer <leo.singer@ligo.org>
6
6
  License-Expression: Apache-2.0
@@ -36,6 +36,13 @@ docs = [
36
36
  source = "https://git.ligo.org/ultra-swift/pytest-kafka-broker"
37
37
  documentation = "https://pytest-kafka-broker.readthedocs.io/"
38
38
 
39
+ [tool.coverage.paths]
40
+ # map paths from installed locations back to project source
41
+ source = [
42
+ "src/pytest_kafka_broker", # <-- source path
43
+ "*/pytest_kafka_broker/", # <-- any installed path
44
+ ]
45
+
39
46
  [tool.mypy]
40
47
  exclude = [
41
48
  "^docs/conf.py$",
@@ -2,7 +2,9 @@ import asyncio
2
2
  import subprocess
3
3
  from collections.abc import AsyncGenerator
4
4
  from dataclasses import dataclass
5
+ from errno import EADDRINUSE
5
6
  from pathlib import Path
7
+ from socket import socket
6
8
  from tarfile import TarFile
7
9
  from tempfile import TemporaryDirectory
8
10
  from uuid import uuid4
@@ -75,6 +77,36 @@ config
75
77
  """
76
78
 
77
79
 
80
+ def _unused_tcp_port(default: int = 0) -> int:
81
+ with socket() as sock:
82
+ try:
83
+ sock.bind(("127.0.0.1", default))
84
+ except OSError as e:
85
+ if e.errno != EADDRINUSE:
86
+ raise
87
+ sock.bind(("127.0.0.1", 0))
88
+ _, port = sock.getsockname()
89
+ return port
90
+
91
+
92
+ @pytest.fixture
93
+ def find_unused_tcp_port():
94
+ """Unused TCP port factory.
95
+
96
+ This is similar to `unused_tcp_port_factory` from pytest_asyncio, but it
97
+ supports a default port argument, and is not session-scoped.
98
+ """
99
+ used = set()
100
+
101
+ def factory(default: int = 0) -> int:
102
+ while (port := _unused_tcp_port(default)) in used:
103
+ pass
104
+ used.add(port)
105
+ return port
106
+
107
+ return factory
108
+
109
+
78
110
  @dataclass
79
111
  class KafkaBrokerContext:
80
112
  """Information and convenience methods for a temporary Kafka cluster.
@@ -120,7 +152,7 @@ del _doc
120
152
 
121
153
  @pytest_asyncio.fixture
122
154
  async def kafka_broker(
123
- kafka_home, tmp_path, unused_tcp_port_factory
155
+ kafka_home, tmp_path, find_unused_tcp_port
124
156
  ) -> AsyncGenerator[KafkaBrokerContext]:
125
157
  """Pytest fixture to run a local, temporary Kafka broker."""
126
158
  kafka_storage = kafka_home / "bin" / "kafka-storage.sh"
@@ -131,8 +163,8 @@ async def kafka_broker(
131
163
  log_path = tmp_path / "log"
132
164
  log_path.mkdir()
133
165
  env = {"LOG_DIR": str(log_path)}
134
- plaintext_port = unused_tcp_port_factory()
135
- controller_port = unused_tcp_port_factory()
166
+ plaintext_port = find_unused_tcp_port(9092)
167
+ controller_port = find_unused_tcp_port(9093)
136
168
  config_path.write_text(
137
169
  f"""
138
170
  process.roles=broker,controller
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-kafka-broker
3
- Version: 0.3.1
3
+ Version: 0.4.0
4
4
  Summary: Pytest plugin to run a single-broker Kafka cluster
5
5
  Author-email: Leo Singer <leo.singer@ligo.org>
6
6
  License-Expression: Apache-2.0