Skip to content

Commit aae7b02

Browse files
committed
Add tests for endpoints json mode
1 parent 811468c commit aae7b02

3 files changed

Lines changed: 50 additions & 879 deletions

File tree

src/together/lib/cli/api/endpoints/create.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ def create(
149149
or "the selected configuration" in error_msg
150150
or "hardware is required" in error_msg
151151
):
152-
click.secho("Invalid hardware selected.", fg="red", err=True)
153-
click.echo("\nAvailable hardware options:")
152+
click.secho("Invalid hardware selected.", fg="red", err=True, file=sys.stderr)
153+
click.echo("\nAvailable hardware options:", file=sys.stderr)
154154
ctx.invoke(list_hardware, available=True, model=model, json=False)
155155
sys.exit(1)
156156
elif "model" in error_msg and (
@@ -162,14 +162,17 @@ def create(
162162
click.echo(
163163
f"Error: Model '{model}' was not found or is not available for dedicated endpoints.",
164164
err=True,
165+
file=sys.stderr,
165166
)
166167
click.echo(
167168
"Please check that the model name is correct and that it supports dedicated endpoint deployment.",
168169
err=True,
170+
file=sys.stderr,
169171
)
170172
click.echo(
171173
"You can browse available models at: https://api.together.ai/models",
172174
err=True,
175+
file=sys.stderr,
173176
)
174177
sys.exit(1)
175178
raise e

tests/cli/test_endpoints.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
from __future__ import annotations
4+
5+
import subprocess
6+
import json
7+
import os
8+
9+
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
10+
11+
def run_command(command: str) -> subprocess.CompletedProcess[str]:
12+
return subprocess.run(["together", "--base-url", base_url, "endpoints", *command.split(" "), "--json"], capture_output=True, text=True)
13+
14+
def assert_command_returns_json(command: str) -> None:
15+
result = run_command(command)
16+
assert result.returncode == 0
17+
assert result.stdout is not None
18+
assert json.loads(result.stdout) is not None
19+
20+
class TestEndpoints:
21+
def test_json_mode_is_supported(self) -> None:
22+
assert_command_returns_json("hardware")
23+
assert_command_returns_json("hardware --model deepseek-ai/DeepSeek-R1")
24+
assert_command_returns_json("availability-zones")
25+
assert_command_returns_json("list")
26+
assert_command_returns_json("list --type dedicated")
27+
assert_command_returns_json("list --usage-type on-demand")
28+
assert_command_returns_json("list --usage-type reserved")
29+
assert_command_returns_json("list --mine")
30+
assert_command_returns_json("create --model deepseek-ai/DeepSeek-R1 --hardware 1x_nvidia_a100_80gb_sxm")
31+
assert_command_returns_json("delete endpoint-123")
32+
assert_command_returns_json("start endpoint-123")
33+
assert_command_returns_json("stop endpoint-123")
34+
assert_command_returns_json("retrieve endpoint-123")
35+
assert_command_returns_json("update endpoint-123 --min-replicas 2 --max-replicas 4 --inactive-timeout 60")
36+
37+
def test_create_requires_model(self) -> None:
38+
result = run_command("create")
39+
assert result.returncode == 2
40+
assert "Error: Missing option '--model'." in result.stderr
41+
42+
def test_create_requires_hardware(self) -> None:
43+
result = run_command("create --model deepseek-ai/DeepSeek-R1 --hardware ''")
44+
assert result.returncode == 1
45+
assert "Invalid hardware selected." in result.stderr

0 commit comments

Comments
 (0)