1- # type: ignore
21from collections .abc import Generator
32from collections .abc import Sequence
43import json
@@ -90,6 +89,8 @@ async def test_create_study(mcp: OptunaMCP) -> None:
9089async def test_get_all_study_names (mcp : OptunaMCP ) -> None :
9190 result = await mcp .call_tool ("get_all_study_names" , arguments = {})
9291 assert len (result ) == 2
92+ assert isinstance (result , Sequence )
93+ assert isinstance (result [0 ], list )
9394 if mcp .storage is None :
9495 assert isinstance (result [0 ][0 ], TextContent )
9596 assert result [0 ][0 ].text == "No storage specified."
@@ -115,6 +116,7 @@ async def test_ask(mcp: OptunaMCP, search_space: dict) -> None:
115116 result = await mcp .call_tool ("ask" , arguments = {"search_space" : search_space })
116117 assert isinstance (result , Sequence )
117118 assert len (result ) == 2
119+ assert isinstance (result [0 ], list )
118120 assert isinstance (result [0 ][0 ], TextContent )
119121 assert isinstance (TrialResponse (** result [1 ]["result" ]), TrialResponse )
120122 assert len (mcp .study .trials ) == 1
@@ -140,6 +142,7 @@ async def test_tell(mcp: OptunaMCP, directions: list[str], values: list[float])
140142 result = await mcp .call_tool ("tell" , arguments = {"trial_number" : t .number , "values" : values })
141143 assert isinstance (result , Sequence )
142144 assert len (result ) == 2
145+ assert isinstance (result [0 ], list )
143146 assert isinstance (result [0 ][0 ], TextContent )
144147 assert isinstance (TrialResponse (** result [1 ]), TrialResponse )
145148 assert len (mcp .study .trials ) == 1
@@ -156,6 +159,7 @@ async def test_set_sampler(mcp: OptunaMCP, sampler_name: str) -> None:
156159 result = await mcp .call_tool ("set_sampler" , arguments = {"name" : sampler_name })
157160 assert isinstance (result , Sequence )
158161 assert len (result ) == 2
162+ assert isinstance (result [0 ], list )
159163 assert isinstance (result [0 ][0 ], TextContent )
160164 assert isinstance (StudyResponse (** result [1 ]), StudyResponse )
161165 assert sampler_name == json .loads (result [0 ][0 ].text )["sampler_name" ]
@@ -174,6 +178,7 @@ async def test_trial_user_attrs(mcp: OptunaMCP) -> None:
174178 result = await mcp .call_tool ("get_trial_user_attrs" , arguments = {"trial_number" : t .number })
175179 assert isinstance (result , Sequence )
176180 assert len (result ) == 2
181+ assert isinstance (result [0 ], list )
177182 assert isinstance (result [0 ][0 ], TextContent )
178183 assert isinstance (TrialResponse (** result [1 ]), TrialResponse )
179184 user_attrs_from_text = json .loads (result [0 ][0 ].text )["user_attrs" ]
@@ -202,6 +207,7 @@ async def test_metric_names(mcp: OptunaMCP, metric_names: list[str]) -> None:
202207 result = await mcp .call_tool ("get_metric_names" , arguments = {})
203208 assert isinstance (result , Sequence )
204209 assert len (result ) == 2
210+ assert isinstance (result [0 ], list )
205211 assert isinstance (result [0 ][0 ], TextContent )
206212 assert isinstance (result [1 ], dict )
207213 user_attrs_from_text = result [0 ][0 ].text
@@ -229,6 +235,7 @@ async def test_get_directions(mcp: OptunaMCP, directions: list[str]) -> None:
229235 result = await mcp .call_tool ("get_directions" , arguments = {})
230236 assert isinstance (result , Sequence )
231237 assert len (result ) == 2
238+ assert isinstance (result [0 ], list )
232239 assert isinstance (result [0 ][0 ], TextContent )
233240 assert isinstance (StudyResponse (** result [1 ]), StudyResponse )
234241
@@ -248,6 +255,7 @@ async def test_get_trials(mcp: OptunaMCP) -> None:
248255 result = await mcp .call_tool ("get_trials" , arguments = {})
249256 assert isinstance (result , Sequence )
250257 assert len (result ) == 2
258+ assert isinstance (result [0 ], list )
251259 assert isinstance (result [0 ][0 ], TextContent )
252260 assert isinstance (result [1 ], dict )
253261 lines_from_text = result [0 ][0 ].text .strip ().split ("\n " )
@@ -269,6 +277,7 @@ async def test_best_trial(mcp: OptunaMCP) -> None:
269277 result = await mcp .call_tool ("best_trial" , arguments = {})
270278 assert isinstance (result , Sequence )
271279 assert len (result ) == 2
280+ assert isinstance (result [0 ], list )
272281 assert isinstance (result [0 ][0 ], TextContent )
273282 assert isinstance (TrialResponse (** result [1 ]), TrialResponse )
274283 assert json .loads (result [0 ][0 ].text )["values" ] == [0.0 ]
@@ -287,6 +296,7 @@ async def test_best_trials(mcp: OptunaMCP) -> None:
287296 result = await mcp .call_tool ("best_trials" , arguments = {})
288297 assert isinstance (result , Sequence )
289298 assert len (result ) == 2
299+ assert isinstance (result [0 ], list )
290300 assert isinstance (result [0 ][0 ], TextContent )
291301 assert isinstance (TrialResponse (** result [1 ]["result" ][0 ]), TrialResponse )
292302
@@ -521,6 +531,7 @@ async def test_launch_optuna_dashboard(
521531 result = await mcp .call_tool ("launch_optuna_dashboard" , arguments = arguments )
522532 assert isinstance (result , Sequence )
523533 assert len (result ) == 2
534+ assert isinstance (result [0 ], list )
524535 assert isinstance (result [0 ][0 ], TextContent )
525536 assert result [0 ][0 ].text .endswith (f":{ expected_port } " )
526537 assert isinstance (result [1 ], dict )
0 commit comments