|
29 | 29 | import shutil |
30 | 30 | import unittest |
31 | 31 |
|
| 32 | +import pytest |
32 | 33 | from huggingface_hub import snapshot_download |
33 | 34 | from openai import BadRequestError, NotFoundError |
| 35 | +from openai_frontend.engine.utils.triton import ( |
| 36 | + _get_vllm_lora_names as get_vllm_lora_names, |
| 37 | +) |
34 | 38 |
|
35 | 39 | from .utils import OpenAIServer |
36 | 40 |
|
37 | 41 |
|
| 42 | +@pytest.mark.parametrize( |
| 43 | + "model_repository,model_name,expect_error", |
| 44 | + [ |
| 45 | + ("openai_model_repository", "", True), # Empty string as model name. |
| 46 | + ("openai_model_repository", " ", True), # Whitespace-only model name. |
| 47 | + ("openai_model_repository", "invalid/path", True), |
| 48 | + ("openai_model_repository", "invalid\\path", True), |
| 49 | + ("openai_model_repository", "../outside/repo", True), |
| 50 | + ("openai_model_repository", "../test_models/identity_py", True), |
| 51 | + ("test_models", "../test_models/identity_py", True), |
| 52 | + ("test_models", "identity_py", False), |
| 53 | + ("test_models", "mock_llm", False), |
| 54 | + ], |
| 55 | +) |
| 56 | +def test_get_vllm_lora_name(model_repository: str, model_name: str, expect_error: bool): |
| 57 | + try: |
| 58 | + get_vllm_lora_names(model_repository, model_name, 1) |
| 59 | + except ValueError as e: |
| 60 | + if expect_error: |
| 61 | + assert ( |
| 62 | + f"Invalid model name: '{model_name}'. Model names must be valid file-system-path segment names." |
| 63 | + == str(e) |
| 64 | + ) |
| 65 | + else: |
| 66 | + raise pytest.fail( |
| 67 | + f"(model_repository='{model_repository}', model_name='{model_name}') raised ValueError unexpectedly: {e}" |
| 68 | + ) |
| 69 | + else: |
| 70 | + if expect_error: |
| 71 | + raise pytest.fail( |
| 72 | + f"(model_repository='{model_repository}', model_name='{model_name}') did not raise ValueError as expected." |
| 73 | + ) |
| 74 | + |
| 75 | + |
38 | 76 | def is_vllm_installed(): |
39 | 77 | try: |
40 | 78 | import vllm as _ |
|
0 commit comments