main
py 39 lines 1.08 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import os
5 from unittest.mock import patch
6
7 import pytest
8
9 from vllm.envs import get_vllm_port
10
11
12 def test_get_vllm_port_not_set():
13 """Test when VLLM_PORT is not set."""
14 with patch.dict(os.environ, {}, clear=True):
15 assert get_vllm_port() is None
16
17
18 def test_get_vllm_port_valid():
19 """Test when VLLM_PORT is set to a valid integer."""
20 with patch.dict(os.environ, {"VLLM_PORT": "5678"}, clear=True):
21 assert get_vllm_port() == 5678
22
23
24 def test_get_vllm_port_invalid():
25 """Test when VLLM_PORT is set to a non-integer value."""
26 with (
27 patch.dict(os.environ, {"VLLM_PORT": "abc"}, clear=True),
28 pytest.raises(ValueError, match="must be a valid integer"),
29 ):
30 get_vllm_port()
31
32
33 def test_get_vllm_port_uri():
34 """Test when VLLM_PORT is set to a URI."""
35 with (
36 patch.dict(os.environ, {"VLLM_PORT": "tcp://localhost:5678"}, clear=True),
37 pytest.raises(ValueError, match="appears to be a URI"),
38 ):
39 get_vllm_port()