# Copyright (c) Huawei Technologies Co., Ltd. 2026-2026. All rights reserved.
# OpenOLC is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# `http://license.coscl.org.cn/MulanPSL2`
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
import os
import unittest
from olc.utils.path_utils import PathUtils
class TestPathUtils(unittest.TestCase):
def setUp(self):
# 保存原始环境变量
self.original_env = os.environ.copy()
def tearDown(self):
# 恢复原始环境变量
os.environ.clear()
os.environ.update(self.original_env)
def test_get_config_path_with_default(self):
# 测试默认配置路径
path = PathUtils.get_config_path()
self.assertTrue(path.endswith(os.sep))
# 默认路径应该是 ../conf/
def test_get_config_path_with_env(self):
# 设置环境变量
test_path = "/custom/config/path"
os.environ["OLC_CONFIG_PATH"] = test_path
# 测试从环境变量获取配置路径
path = PathUtils.get_config_path()
self.assertTrue(path.endswith(os.sep))
# 检查路径是否包含 test_path(可能会被 os.path.normpath 处理)
normalized_test_path = os.path.normpath(test_path)
self.assertTrue(normalized_test_path in path)
if __name__ == '__main__':
unittest.main()