Files
xc-llm-ascend/tests/ut/test_envs.py
YuanCheng-coder ddaded1537 Add ut for envs.py (#2131)
What this PR does / why we need it?
test vllm_ascend/envs.py contains environment variables defination

Does this PR introduce any user-facing change?
N/A

How was this patch tested?
CI passed with new added test.

vLLM version: v0.10.0
vLLM main:
9532a6d563

- vLLM version: v0.10.0
- vLLM main:
b4e081cb15

---------

Signed-off-by: chengyuan <chengyuan27@huawei.com>
Co-authored-by: chengyuan <chengyuan27@huawei.com>
2025-08-02 16:53:44 +08:00

62 lines
2.2 KiB
Python

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file is a part of the vllm-ascend project.
import inspect
import os
from tests.ut.base import TestBase
from vllm_ascend import envs
class TestEnvVariables(TestBase):
def setUp(self):
self.env_vars = list(envs.env_variables.keys())
def test_env_vars_behavior(self):
for var_name in self.env_vars:
with self.subTest(var=var_name):
original_val = os.environ.get(var_name)
var_handler = envs.env_variables[var_name]
try:
if var_name in os.environ:
del os.environ[var_name]
self.assertEqual(getattr(envs, var_name), var_handler())
handler_source = inspect.getsource(var_handler)
if 'int(' in handler_source:
test_vals = ["123", "456"]
elif 'bool(int(' in handler_source:
test_vals = ["0", "1"]
else:
test_vals = [f"test_{var_name}", f"custom_{var_name}"]
for test_val in test_vals:
os.environ[var_name] = test_val
self.assertEqual(getattr(envs, var_name),
var_handler())
finally:
if original_val is None:
os.environ.pop(var_name, None)
else:
os.environ[var_name] = original_val
def test_dir_and_getattr(self):
self.assertEqual(sorted(envs.__dir__()), sorted(self.env_vars))
for var_name in self.env_vars:
with self.subTest(var=var_name):
getattr(envs, var_name)