From b0eccc517194a2d9b3f65928df553ac8d246b2d1 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 21 May 2026 22:21:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=20bin=20=E6=A8=A1=E5=9D=97=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=EF=BC=88+19=20=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - format_size / get_log_base_names 纯函数测试 - parse_args 命令行参数解析测试 - manage_logs / run_cli 函数签名验证 - bin 子模块存在性测试 Co-Authored-By: Claude Opus 4.5 --- tests/test_bin_modules.py | 139 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 tests/test_bin_modules.py diff --git a/tests/test_bin_modules.py b/tests/test_bin_modules.py new file mode 100644 index 0000000..47e9105 --- /dev/null +++ b/tests/test_bin_modules.py @@ -0,0 +1,139 @@ +"""bin 模块单元测试。 + +覆盖: +- manage_logs: format_size, get_log_base_names 纯函数 +- run_cli: parse_args 函数 +""" + +from __future__ import annotations + +import argparse +import pytest + + +class TestFormatSize: + """format_size 纯函数测试。""" + + def test_small_size(self): + from bin.manage_logs import format_size + + result = format_size(0.5) + assert "MB" in result or "KB" in result or "0" in result + + def test_medium_size(self): + from bin.manage_logs import format_size + + result = format_size(100.0) + assert isinstance(result, str) + + def test_large_size(self): + from bin.manage_logs import format_size + + result = format_size(1500.0) + assert isinstance(result, str) + assert "GB" in result or "1" in result + + def test_zero_size(self): + from bin.manage_logs import format_size + + result = format_size(0.0) + assert isinstance(result, str) + + +class TestGetLogBaseNames: + """get_log_base_names 函数测试。""" + + def test_function_exists(self): + from bin.manage_logs import get_log_base_names + + assert callable(get_log_base_names) + + def test_nonexistent_dir_returns_empty(self): + from bin.manage_logs import get_log_base_names + + result = get_log_base_names('/nonexistent/path') + assert result == [] + + +class TestManageLogsModule: + """manage_logs 模块测试。""" + + def test_show_stats_exists(self): + from bin.manage_logs import show_stats + + assert callable(show_stats) + + def test_manual_cleanup_exists(self): + from bin.manage_logs import manual_cleanup + + assert callable(manual_cleanup) + + def test_manual_compress_exists(self): + from bin.manage_logs import manual_compress + + assert callable(manual_compress) + + def test_show_monitor_status_exists(self): + from bin.manage_logs import show_monitor_status + + assert callable(show_monitor_status) + + def test_main_exists(self): + from bin.manage_logs import main + + assert callable(main) + + +class TestRunCliParseArgs: + """run_cli.parse_args 函数测试。""" + + def test_function_exists(self): + from bin.run_cli import parse_args + + assert callable(parse_args) + + def test_empty_args(self): + from bin.run_cli import parse_args + + result = parse_args([]) + assert isinstance(result, argparse.Namespace) + + def test_device_id_arg(self): + from bin.run_cli import parse_args + + result = parse_args(['--device-id', 'test_device']) + assert result.device_id == 'test_device' + + def test_y_pianyi_arg(self): + from bin.run_cli import parse_args + + result = parse_args(['--y-pianyi', '100']) + assert result.y_pianyi == 100 + + +class TestRunCliModule: + """run_cli 模块测试。""" + + def test_ensure_adb_in_path_exists(self): + from bin.run_cli import ensure_adb_in_path + + assert callable(ensure_adb_in_path) + + def test_main_exists(self): + from bin.run_cli import main + + assert callable(main) + + +class TestBinModules: + """bin 子模块存在性测试。""" + + def test_run_cli_importable(self): + from bin import run_cli + + assert run_cli is not None + + def test_manage_logs_importable(self): + from bin import manage_logs + + assert manage_logs is not None