补 douyin/handlers 模块单元测试(+13 用例)
- _adb_path 纯函数测试(环境变量、引号处理、operation 对象) - SwipeHandler / PopupHandler / ScreenshotHandler 类存在性验证 - swipe_ops 函数签名检查 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cdf8be0ded
commit
6ecedbbde1
1 file changed
+143
@@ -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
|
||||
Reference in new issue
Block a user