4ae33cbe53
- 每个文件补充模块级 docstring、类/函数 docstring、关键逻辑行内注释 - 注释风格:"中文说明" 或 # 中文说明 - 代码结构和逻辑完全不变
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
"""测试应用程序版本号的显示一致性。
|
|
|
|
验证内容:
|
|
- APP_TITLE 使用统一的 __version__ 构建
|
|
- CLI 的 --help 和 --version 输出均使用共享的版本号
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import contextlib
|
|
import io
|
|
import unittest
|
|
|
|
from a1_swap_mod_packer import APP_NAME, APP_TITLE, __version__
|
|
from a1_swap_mod_packer.cli import create_parser
|
|
|
|
|
|
class VersionDisplayTest(unittest.TestCase):
|
|
"""测试版本信息在应用标题和 CLI 中的一致性。"""
|
|
|
|
def test_app_title_uses_shared_version(self) -> None:
|
|
"""验证 APP_TITLE 由 APP_NAME 与 __version__ 拼接而成。"""
|
|
self.assertEqual(APP_TITLE, f"{APP_NAME} v{__version__}")
|
|
|
|
def test_cli_help_and_version_use_shared_version(self) -> None:
|
|
"""验证 CLI 帮助信息和 --version 输出中均包含统一版本号。"""
|
|
parser = create_parser()
|
|
# 帮助信息应包含 APP_TITLE
|
|
self.assertIn(APP_TITLE, parser.format_help())
|
|
|
|
stdout = io.StringIO()
|
|
# --version 参数触发 SystemExit(0) 并打印版本信息
|
|
with self.assertRaises(SystemExit) as caught, contextlib.redirect_stdout(stdout):
|
|
parser.parse_args(["--version"])
|
|
|
|
self.assertEqual(caught.exception.code, 0) # 正常退出码
|
|
self.assertEqual(stdout.getvalue().strip(), f"{APP_NAME} {__version__}") # 版本信息匹配
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|