feat: 内置并统一使用项目 ADB (#149)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""项目内置 ADB 路径与完整性检查测试。"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from src.adb_runtime import (
|
||||
BundledAdbError,
|
||||
REQUIRED_ADB_FILES,
|
||||
bundled_adb_path,
|
||||
configure_bundled_adb_environment,
|
||||
validate_bundled_adb,
|
||||
)
|
||||
|
||||
|
||||
class BundledAdbRuntimeTest(unittest.TestCase):
|
||||
def test_project_adb_is_complete(self):
|
||||
adb_path = validate_bundled_adb()
|
||||
|
||||
self.assertEqual(adb_path, bundled_adb_path())
|
||||
self.assertTrue(adb_path.is_absolute())
|
||||
for file_name in REQUIRED_ADB_FILES:
|
||||
self.assertTrue((adb_path.parent / file_name).is_file())
|
||||
|
||||
def test_missing_file_reports_name_without_path_fallback(self):
|
||||
with tempfile.TemporaryDirectory() as directory, patch(
|
||||
"src.adb_runtime.app_dir", return_value=Path(directory)
|
||||
):
|
||||
with self.assertRaisesRegex(BundledAdbError, "adb.exe"):
|
||||
validate_bundled_adb()
|
||||
|
||||
def test_configure_forces_adbutils_to_use_project_adb(self):
|
||||
old_value = os.environ.get("ADBUTILS_ADB_PATH")
|
||||
try:
|
||||
configured = configure_bundled_adb_environment()
|
||||
self.assertEqual(
|
||||
os.environ["ADBUTILS_ADB_PATH"],
|
||||
str(configured),
|
||||
)
|
||||
finally:
|
||||
if old_value is None:
|
||||
os.environ.pop("ADBUTILS_ADB_PATH", None)
|
||||
else:
|
||||
os.environ["ADBUTILS_ADB_PATH"] = old_value
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user