test_vllm_port.py 1.08 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

import os
from unittest.mock import patch

import pytest

from vllm.envs import get_vllm_port


def test_get_vllm_port_not_set():
    """Test when VLLM_PORT is not set."""
    with patch.dict(os.environ, {}, clear=True):
        assert get_vllm_port() is None


def test_get_vllm_port_valid():
    """Test when VLLM_PORT is set to a valid integer."""
    with patch.dict(os.environ, {"VLLM_PORT": "5678"}, clear=True):
        assert get_vllm_port() == 5678


def test_get_vllm_port_invalid():
    """Test when VLLM_PORT is set to a non-integer value."""
    with (patch.dict(os.environ, {"VLLM_PORT": "abc"}, clear=True),
          pytest.raises(ValueError, match="must be a valid integer")):
        get_vllm_port()


def test_get_vllm_port_uri():
    """Test when VLLM_PORT is set to a URI."""
    with (patch.dict(os.environ, {"VLLM_PORT": "tcp://localhost:5678"},
                     clear=True),
          pytest.raises(ValueError, match="appears to be a URI")):
        get_vllm_port()