Skip to content

Commit 1fd4343

Browse files
committed
Update CLI tests
1 parent 7b4f414 commit 1fd4343

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

antares-python/src/antares/config_loader.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ def load_config(path: str | Path | None = None) -> AntaresSettings:
1717
with config_path.open("rb") as f:
1818
data = tomli.load(f)
1919

20-
return AntaresSettings(**data.get("antares", {}))
20+
return AntaresSettings(
21+
controller_bind_addr=data.get("antares.simulation.controller_bind_addr", "0.0.0.0:17394"),
22+
radar_bind_addr=data.get("antares.simulation.radar_bind_addr", "0.0.0.0:17396"),
23+
)

antares-python/tests/test_cli.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import subprocess
33

44
import pytest
5+
from pydantic import BaseModel
56
from typer.testing import CliRunner
67

78
from antares.cli import app
@@ -14,12 +15,10 @@
1415
def fake_config(tmp_path):
1516
config_file = tmp_path / "config.toml"
1617
config_file.write_text("""
17-
[antares]
18-
host = "localhost"
19-
http_port = 9000
20-
tcp_port = 9001
21-
timeout = 2.0
22-
auth_token = "fake-token"
18+
[antares.simulation]
19+
controller_bind_addr = "10.20.20.10:17394"
20+
[antares.radar]
21+
bind_addr = "0.0.0.0:17396"
2322
""")
2423
return str(config_file)
2524

@@ -138,12 +137,6 @@ async def fake_sub(self):
138137
assert "test-event" in result.output
139138

140139

141-
def test_handle_error_json(monkeypatch):
142-
result = runner.invoke(app, ["reset", "--json"], catch_exceptions=False)
143-
assert result.exit_code in {1, 2}
144-
assert "error" in result.output
145-
146-
147140
def test_build_client_fails(mocker):
148141
mocker.patch("antares.config_loader.load_config", side_effect=Exception("broken config"))
149142
result = runner.invoke(app, ["reset", "--config", "invalid.toml"])
@@ -169,7 +162,18 @@ def test_cli_add_ship_error_handling(mocker, fake_config):
169162

170163
result = runner.invoke(
171164
app,
172-
["add-ship", "--type", "stationary", "--x", "1", "--y", "2", "--config", fake_config],
165+
[
166+
"add-ship",
167+
"--type",
168+
"stationary",
169+
"--x",
170+
"1",
171+
"--y",
172+
"2",
173+
"--config",
174+
fake_config,
175+
"--json",
176+
],
173177
)
174178

175179
expected_exit_code = 2
@@ -308,7 +312,10 @@ def test_cli_verbose_prints_config(mocker, fake_config):
308312
assert "Using settings" in result.output
309313

310314

311-
def test_cli_subscribe_json(monkeypatch, fake_config):
315+
def test_cli_subscribe_json(monkeypatch):
316+
class EventMock(BaseModel):
317+
event: str
318+
312319
class OneEventGen:
313320
def __init__(self):
314321
self.done = False
@@ -319,15 +326,15 @@ def __aiter__(self):
319326
async def __anext__(self):
320327
if not self.done:
321328
self.done = True
322-
return {"event": "test"}
329+
return EventMock(event="test")
323330
raise StopAsyncIteration
324331

325332
monkeypatch.setattr("antares.client.tcp.TCPSubscriber.subscribe", lambda self: OneEventGen())
326333

327-
result = runner.invoke(app, ["subscribe", "--config", fake_config, "--json"])
334+
result = runner.invoke(app, ["subscribe", "--json"])
328335

329336
assert result.exit_code == 0
330-
assert '{"event": "test"}' in result.output
337+
assert '{"event":"test"}' in result.output
331338

332339

333340
def test_start_success(mocker):

0 commit comments

Comments
 (0)