Skip to content

Commit 28808fe

Browse files
authored
Merge pull request #131 from VectorInstitute/fix-json-format
Fix json format for launch command
2 parents e28a9d3 + 284454f commit 28808fe

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
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: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
handling the presentation of model information, status updates, and metrics.
55
"""
66

7+
import json
78
from pathlib import Path
89
from typing import Any, Union
910

@@ -27,9 +28,8 @@ class LaunchResponseFormatter:
2728
Parameters
2829
----------
2930
model_name : str
30-
Name of the launched model
31-
params : dict[str, Any]
32-
Launch parameters and configuration
31+
Name of the launched model params : dict[str, Any] Launch parameters and
32+
configuration
3333
"""
3434

3535
def __init__(self, model_name: str, params: dict[str, Any]):
@@ -176,7 +176,12 @@ def output_json(self) -> None:
176176
json_data["pending_reason"] = self.status_info.pending_reason
177177
if self.status_info.failed_reason:
178178
json_data["failed_reason"] = self.status_info.failed_reason
179-
click.echo(json_data)
179+
180+
# Convert dict to json compliant string with double quotes
181+
json_string = json.dumps(json_data)
182+
183+
# Output json to console
184+
click.echo(json_string)
180185

181186
def output_table(self) -> Table:
182187
"""Create and display rich table.

0 commit comments

Comments
 (0)