Skip to content

Commit 4b4c676

Browse files
committed
test: Add Validator
This change adds a test to validate that the modification provides the expected outcome.
1 parent 4653f77 commit 4b4c676

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

python/openai/tests/test_lora.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import json
2828
import os
29+
import pytest
2930
import shutil
3031
import unittest
3132

@@ -34,6 +35,10 @@
3435

3536
from .utils import OpenAIServer
3637

38+
from ..openai_frontend.engine.utils.triton import (
39+
_get_vllm_lora_names as get_vllm_lora_names,
40+
)
41+
3742

3843
def is_vllm_installed():
3944
try:
@@ -361,5 +366,39 @@ def test_lora_separator_set_for_non_vllm_formatted_models(self):
361366
self._test_chat_completion(client, "doll")
362367

363368

369+
@pytest.mark.parametrize(
370+
"model_repository,model_name,expect_error",
371+
[
372+
("openai_model_repository", "", True), # Empty string as model name.
373+
("openai_model_repository", " ", True), # Whitespace-only model name.
374+
("openai_model_repository", "invalid/path", True),
375+
("openai_model_repository", "invalid\\path", True),
376+
("openai_model_repository", "../outside/repo", True),
377+
("test_models", "identity_py", False),
378+
("test_models", "mock_llm", False),
379+
],
380+
)
381+
def test_get_vllm_lora_name(
382+
self, model_repository: str, model_name: str, expect_error: bool
383+
):
384+
try:
385+
get_vllm_lora_names(model_repository, model_name, 1)
386+
except ValueError as e:
387+
if expect_error:
388+
self.assertEqual(
389+
f"Invalid model name: '{model_name}'. Model names must be valid file-system-path segment names.",
390+
str(e),
391+
)
392+
else:
393+
raise pytest.fail(
394+
f"(model_repository='{model_repository}', model_name='{model_name}') raised ValueError unexpectedly: {e}"
395+
)
396+
else:
397+
if expect_error:
398+
raise pytest.fail(
399+
f"(model_repository='{model_repository}', model_name='{model_name}') did not raise ValueError as expected."
400+
)
401+
402+
364403
if __name__ == "__main__":
365404
unittest.main()

0 commit comments

Comments
 (0)