From 6ecedbbde1982fdf0b9a26578e9befed73604a91 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 21 May 2026 21:50:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=20douyin/handlers=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=EF=BC=88+13=20?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _adb_path 纯函数测试(环境变量、引号处理、operation 对象) - SwipeHandler / PopupHandler / ScreenshotHandler 类存在性验证 - swipe_ops 函数签名检查 Co-Authored-By: Claude Opus 4.5 --- tests/test_handlers.py | 143 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 tests/test_handlers.py diff --git a/tests/test_handlers.py b/tests/test_handlers.py new file mode 100644 index 0000000..e769f60 --- /dev/null +++ b/tests/test_handlers.py @@ -0,0 +1,143 @@ +"""douyin/handlers 模块单元测试。 + +覆盖: +- douyin_swipe_ops: _adb_path 纯函数 +- SwipeHandler 类存在性验证 +""" + +from __future__ import annotations + +import os +import pytest + + +class TestAdbPath: + """_adb_path 纯函数测试。""" + + def test_default_returns_adb(self): + from douyin.handlers.douyin_swipe_ops import _adb_path + + # 清除环境变量 + old = os.environ.pop("ADB_EXECUTABLE", None) + try: + result = _adb_path(None) + assert result == "adb" + finally: + if old is not None: + os.environ["ADB_EXECUTABLE"] = old + + def test_respects_env_var(self): + from douyin.handlers.douyin_swipe_ops import _adb_path + + old = os.environ.get("ADB_EXECUTABLE") + try: + os.environ["ADB_EXECUTABLE"] = "/custom/path/adb" + result = _adb_path(None) + assert result == "/custom/path/adb" + finally: + if old is not None: + os.environ["ADB_EXECUTABLE"] = old + else: + os.environ.pop("ADB_EXECUTABLE", None) + + def test_strips_quotes_from_env_var(self): + from douyin.handlers.douyin_swipe_ops import _adb_path + + old = os.environ.get("ADB_EXECUTABLE") + try: + os.environ["ADB_EXECUTABLE"] = '"/path/with spaces/adb"' + result = _adb_path(None) + assert result == "/path/with spaces/adb" + finally: + if old is not None: + os.environ["ADB_EXECUTABLE"] = old + else: + os.environ.pop("ADB_EXECUTABLE", None) + + def test_uses_operation_adb_path_if_available(self): + from douyin.handlers.douyin_swipe_ops import _adb_path + + class MockOperation: + def _adb_path(self): + return "/mock/adb" + + result = _adb_path(MockOperation()) + assert result == "/mock/adb" + + def test_ignores_operation_without_adb_path(self): + from douyin.handlers.douyin_swipe_ops import _adb_path + + class MockOperationNoMethod: + pass + + old = os.environ.pop("ADB_EXECUTABLE", None) + try: + result = _adb_path(MockOperationNoMethod()) + assert result == "adb" + finally: + if old is not None: + os.environ["ADB_EXECUTABLE"] = old + + +class TestSwipeHandler: + """SwipeHandler 类测试。""" + + def test_class_exists(self): + from douyin.handlers.douyin_swipe_handler import SwipeHandler + + assert SwipeHandler is not None + + def test_class_is_importable(self): + from douyin.handlers import douyin_swipe_handler + + assert hasattr(douyin_swipe_handler, "SwipeHandler") + + +class TestSwipeOps: + """douyin_swipe_ops 模块测试。""" + + def test_swipe_functions_exist(self): + from douyin.handlers.douyin_swipe_ops import ( + swipe_up_switch_live, + swipe_down_back_live, + ) + + assert callable(swipe_up_switch_live) + assert callable(swipe_down_back_live) + + def test_adb_swipe_direct_exists(self): + from douyin.handlers.douyin_swipe_ops import _adb_swipe_direct + + assert callable(_adb_swipe_direct) + + +class TestPopupHandler: + """PopupHandler 类测试。""" + + def test_module_importable(self): + from douyin.handlers import douyin_popup_handler + + assert douyin_popup_handler is not None + + def test_class_exists(self): + from douyin.handlers.douyin_popup_handler import PopupHandler + + assert PopupHandler is not None + + +class TestScreenshotHandler: + """ScreenshotHandler 类测试。""" + + def test_module_importable(self): + from douyin.handlers import douyin_screenshot_handler + + assert douyin_screenshot_handler is not None + + +class TestScreenshotManager: + """ScreenshotManager 类测试。""" + + def test_module_importable(self): + from douyin.handlers import douyin_screenshot_manager + + assert douyin_screenshot_manager is not None