22import subprocess
33
44import pytest
5+ from pydantic import BaseModel
56from typer .testing import CliRunner
67
78from antares .cli import app
1415def 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-
147140def 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
333340def test_start_success (mocker ):
0 commit comments