Skip to content

Commit 284454f

Browse files
committed
Fixed some tests and formatting errors
1 parent 9575fdc commit 284454f

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

tests/vec_inf/cli/test_helper.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for the CLI helper classes."""
22

3+
import json
34
from unittest.mock import MagicMock, patch
45

56
from rich.console import Console
@@ -218,10 +219,11 @@ def test_output_json_ready_status(self, mock_echo):
218219
formatter.output_json()
219220

220221
mock_echo.assert_called_once()
221-
# Just check that it was called with a dict
222+
# Just check that it was called with a json compatible string
222223
output = mock_echo.call_args[0][0]
223-
assert isinstance(output, dict)
224-
assert "model_name" in output
224+
json_dict = json.loads(output)
225+
assert isinstance(json_dict, dict)
226+
assert "model_name" in json_dict
225227

226228
@patch("click.echo")
227229
def test_output_json_with_error_reasons(self, mock_echo):
@@ -242,9 +244,10 @@ def test_output_json_with_error_reasons(self, mock_echo):
242244

243245
mock_echo.assert_called_once()
244246
output = mock_echo.call_args[0][0]
245-
assert isinstance(output, dict)
246-
assert "pending_reason" in output
247-
assert "failed_reason" in output
247+
json_dict = json.loads(output)
248+
assert isinstance(json_dict, dict)
249+
assert "pending_reason" in json_dict
250+
assert "failed_reason" in json_dict
248251

249252

250253
class TestMetricsResponseFormatter:

vec_inf/cli/_helper.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class LaunchResponseFormatter:
2828
Parameters
2929
----------
3030
model_name : str
31-
Name of the launched model params : dict[str, Any] Launch parameters and configuration
31+
Name of the launched model params : dict[str, Any] Launch parameters and
32+
configuration
3233
"""
3334

3435
def __init__(self, model_name: str, params: dict[str, Any]):
@@ -115,14 +116,28 @@ def format_table_output(self) -> Table:
115116
for model_name in self.params["models"]:
116117
table.add_row("Model Name", model_name, style="magenta")
117118
# Add resource allocation details
118-
table.add_row("Partition", f" {self.params['models'][model_name]['partition']}")
119+
table.add_row(
120+
"Partition", f" {self.params['models'][model_name]['partition']}"
121+
)
119122
table.add_row("QoS", f" {self.params['models'][model_name]['qos']}")
120-
table.add_row("Time Limit", f" {self.params['models'][model_name]['time']}")
121-
table.add_row("Num Nodes", f" {self.params['models'][model_name]['num_nodes']}")
122-
table.add_row("GPUs/Node", f" {self.params['models'][model_name]['gpus_per_node']}")
123-
table.add_row("CPUs/Task", f" {self.params['models'][model_name]['cpus_per_task']}")
124-
table.add_row("Memory/Node", f" {self.params['models'][model_name]['mem_per_node']}")
125-
table.add_row("Log Directory", f" {self.params['models'][model_name]['log_dir']}")
123+
table.add_row(
124+
"Time Limit", f" {self.params['models'][model_name]['time']}"
125+
)
126+
table.add_row(
127+
"Num Nodes", f" {self.params['models'][model_name]['num_nodes']}"
128+
)
129+
table.add_row(
130+
"GPUs/Node", f" {self.params['models'][model_name]['gpus_per_node']}"
131+
)
132+
table.add_row(
133+
"CPUs/Task", f" {self.params['models'][model_name]['cpus_per_task']}"
134+
)
135+
table.add_row(
136+
"Memory/Node", f" {self.params['models'][model_name]['mem_per_node']}"
137+
)
138+
table.add_row(
139+
"Log Directory", f" {self.params['models'][model_name]['log_dir']}"
140+
)
126141

127142
return table
128143

@@ -342,7 +357,9 @@ def __init__(self, console: Console, json_mode: bool = False):
342357
self.model_config = None
343358
self.model_names: list[str] = []
344359

345-
def _format_single_model_output(self, config: ModelConfig) -> Union[dict[str, Any], Table]:
360+
def _format_single_model_output(
361+
self, config: ModelConfig
362+
) -> Union[dict[str, Any], Table]:
346363
"""Format output table for a single model.
347364
348365
Parameters
@@ -360,7 +377,9 @@ def _format_single_model_output(self, config: ModelConfig) -> Union[dict[str, An
360377
excluded = {"venv", "log_dir"}
361378
config_dict = config.model_dump(exclude=excluded)
362379
# Convert Path objects to strings
363-
config_dict["model_weights_parent_dir"] = str(config_dict["model_weights_parent_dir"])
380+
config_dict["model_weights_parent_dir"] = str(
381+
config_dict["model_weights_parent_dir"]
382+
)
364383
return config_dict
365384

366385
table = create_table(key_title="Model Config", value_title="Value")
@@ -373,7 +392,9 @@ def _format_single_model_output(self, config: ModelConfig) -> Union[dict[str, An
373392
table.add_row(f" {vllm_arg}:", str(vllm_value))
374393
return table
375394

376-
def _format_all_models_output(self, model_infos: list[ModelInfo]) -> Union[list[str], list[Panel]]:
395+
def _format_all_models_output(
396+
self, model_infos: list[ModelInfo]
397+
) -> Union[list[str], list[Panel]]:
377398
"""Format output table for all models.
378399
379400
Parameters

0 commit comments

Comments
 (0)