This commit is contained in:
Dhruvil Mistry 2026-11-07 03:37:31 +00:00 • committed by GitHub
commit 01dc7ed54d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 9 deletions

View file

@ -336,8 +336,6 @@ class ProxyInitializationHelpers:
api_base = f"http://{host}:{port}"
if isinstance(test, str):
api_base = test
else:
raise ValueError("Invalid test value")
client: Final = openai.OpenAI(api_key="My API Key", base_url=api_base)
response: Final = client.chat.completions.create(

View file

@ -197,23 +197,27 @@ class TestProxyInitializationHelpers:
mock_client.chat.completions.create.side_effect = [
mock_response,
mock_stream_response,
mock_response,
mock_stream_response,
]
# Execute
with pytest.raises(ValueError, match="Invalid test value"):
ProxyInitializationHelpers._run_test_chat_completion(
"localhost", 8000, "gpt-3.5-turbo", True
)
# The --test flag passes True; the helper must fall back to http://{host}:{port}
ProxyInitializationHelpers._run_test_chat_completion(
"localhost", 8000, "gpt-3.5-turbo", True
)
# Test with valid string test value
# Test with explicit string test value
ProxyInitializationHelpers._run_test_chat_completion(
"localhost", 8000, "gpt-3.5-turbo", "http://test-url"
)
# Assert
mock_openai.assert_called_once_with(
api_key="My API Key", base_url="http://test-url"
assert mock_openai.call_count == 2
mock_openai.assert_any_call(
api_key="My API Key", base_url="http://localhost:8000"
)
mock_openai.assert_any_call(api_key="My API Key", base_url="http://test-url")
mock_client.chat.completions.create.assert_called()
def test_get_default_unvicorn_init_args(self):