Skip to content

Commit 72af19a

Browse files
committed
Format ./nats-server
1 parent 8634fd8 commit 72af19a

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

nats-server/src/nats/server/__init__.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
FATAL_PATTERN = re.compile(r"\[FTL\]\s+(.*)")
3535
INFO_PATTERN = re.compile(r"\[INF\]\s+(.*)")
3636
READY_PATTERN = re.compile(r"Server is ready")
37-
LISTENING_PATTERN = re.compile(
38-
r"Listening for client connections on (.+):(\d+)"
39-
)
37+
LISTENING_PATTERN = re.compile(r"Listening for client connections on (.+):(\d+)")
4038

4139

4240
class ServerError(Exception):
@@ -279,7 +277,7 @@ async def wait_ready() -> tuple[str, int]:
279277

280278
if match := LISTENING_PATTERN.search(stderr_line):
281279
host_part = match.group(1)
282-
if host_part.startswith('[') and host_part.endswith(']'):
280+
if host_part.startswith("[") and host_part.endswith("]"):
283281
host = host_part[1:-1]
284282
else:
285283
host = host_part
@@ -298,13 +296,11 @@ async def wait_ready() -> tuple[str, int]:
298296
if returncode != 0:
299297
msg = f"Server exited with code {returncode}"
300298
if error_lines:
301-
errors = '\n'.join(error_lines)
299+
errors = "\n".join(error_lines)
302300
msg += f"\nErrors:\n{errors}"
303301
raise ServerError(msg)
304302

305-
raise ServerError(
306-
"Server ended without becoming ready"
307-
) # pragma: no cover
303+
raise ServerError("Server ended without becoming ready") # pragma: no cover
308304

309305
return await asyncio.wait_for(wait_ready(), timeout=timeout)
310306

@@ -413,14 +409,14 @@ async def run_cluster(
413409
node_store_dir = None
414410
if jetstream and store_dir:
415411
# Use as base directory and create subdirectory for each node
416-
node_store_dir = os.path.join(store_dir, f"node{i+1}")
412+
node_store_dir = os.path.join(store_dir, f"node{i + 1}")
417413
os.makedirs(node_store_dir, exist_ok=True)
418414

419415
server = await _run_cluster_node(
420416
config_path=config_path,
421417
port=available_ports[i],
422418
routes=routes,
423-
name=f"node{i+1}",
419+
name=f"node{i + 1}",
424420
cluster_name="cluster",
425421
cluster_port=cluster_ports[i],
426422
jetstream=jetstream,
@@ -465,9 +461,7 @@ async def _run_cluster_node(
465461
"""
466462
# Build cluster URL and routes string for CLI
467463
cluster_url = f"nats://127.0.0.1:{cluster_port}"
468-
routes_str = ",".join(
469-
f"nats://127.0.0.1:{r}" for r in routes
470-
) if routes else None
464+
routes_str = ",".join(f"nats://127.0.0.1:{r}" for r in routes) if routes else None
471465

472466
process = await _create_server_process(
473467
port=port,
@@ -480,8 +474,6 @@ async def _run_cluster_node(
480474
config_path=config_path if config_path else None,
481475
)
482476

483-
assigned_host, assigned_port = await _wait_for_server_ready(
484-
process, timeout=10.0
485-
)
477+
assigned_host, assigned_port = await _wait_for_server_ready(process, timeout=10.0)
486478

487479
return Server(process, assigned_host, assigned_port)

nats-server/tests/conftest.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
def get_nats_server_version():
1515
"""Get the nats-server version or fail if not installed."""
1616
try:
17-
result = subprocess.run(["nats-server", "--version"],
18-
capture_output=True,
19-
check=True,
20-
text=True)
17+
result = subprocess.run(
18+
["nats-server", "--version"], capture_output=True, check=True, text=True
19+
)
2120
return result.stdout.strip() or result.stderr.strip()
2221
except (subprocess.SubprocessError, FileNotFoundError) as e:
2322
pytest.fail(f"nats-server is not installed or not in PATH: {e}")

nats-server/tests/test_server.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ServerInfo(TypedDict):
1818
1919
See: https://docs.nats.io/reference/reference-protocols/nats-protocol#info
2020
"""
21+
2122
# Required fields
2223
server_id: str
2324
server_name: str
@@ -264,9 +265,7 @@ async def test_run_with_store_dir_as_file(tmp_path):
264265

265266
# Try to start server with JetStream using a file as store_dir
266267
with pytest.raises(ServerError) as exc_info:
267-
await run(
268-
port=0, jetstream=True, store_dir=str(store_file), timeout=2.0
269-
)
268+
await run(port=0, jetstream=True, store_dir=str(store_file), timeout=2.0)
270269

271270
# Verify the error message indicates the storage directory issue
272271
error_msg = str(exc_info.value).lower()
@@ -522,9 +521,7 @@ async def test_cluster_with_conflicting_config(tmp_path):
522521
"""Test run_cluster with config that includes cluster settings."""
523522
# The function should still work, merging config with generated cluster setup
524523
cluster = await run_cluster(
525-
"tests/configs/jetstream.conf",
526-
jetstream=True,
527-
store_dir=str(tmp_path)
524+
"tests/configs/jetstream.conf", jetstream=True, store_dir=str(tmp_path)
528525
)
529526

530527
try:
@@ -549,8 +546,10 @@ async def test_run_with_invalid_host():
549546
with pytest.raises(ServerError) as exc_info:
550547
await run(host="999.999.999.999", port=0, timeout=2.0)
551548

552-
assert "exited" in str(exc_info.value
553-
).lower() or "error" in str(exc_info.value).lower()
549+
assert (
550+
"exited" in str(exc_info.value).lower()
551+
or "error" in str(exc_info.value).lower()
552+
)
554553

555554

556555
async def test_cluster_client_url():

0 commit comments

Comments
 (0)