Skip to content

The only downloader you need. 下载器的集大成者。

test(android): 检查 Android cfg 函数签名与桌面端一致

XiaoYouChR5a23e148fdd8
diff --git a/tests/test_android_config_parity.py b/tests/test_android_config_parity.py
index 41c86f55..f3a0a9ad 100644
--- a/tests/test_android_config_parity.py
+++ b/tests/test_android_config_parity.py
@@ -1,10 +1,13 @@
from __future__ import annotations
import importlib.util
+import inspect
from pathlib import Path
from app.config.cfg import Config
+desktopCfg = importlib.import_module("app.config.cfg")
+
ANDROID_CFG_PATH = Path(__file__).parents[1] / "android/app/src/main/python/app/config/cfg.py"
# 桌面窗口/Dock/菜单栏/开机自启/URL scheme/剪贴板监听/下载目录历史/设置页折叠状态;
@@ -28,11 +31,11 @@ DESKTOP_ONLY = {
}
-def loadAndroidConfig():
+def loadAndroidCfg():
spec = importlib.util.spec_from_file_location("android_cfg", ANDROID_CFG_PATH)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
- return module.AndroidConfig
+ return module
def keysOf(configClass) -> set[tuple[str, str]]:
@@ -44,5 +47,19 @@ def keysOf(configClass) -> set[tuple[str, str]]:
def test_android_config_covers_every_desktop_setting_except_desktop_only():
- missing = keysOf(Config) - keysOf(loadAndroidConfig()) - DESKTOP_ONLY
+ missing = keysOf(Config) - keysOf(loadAndroidCfg().AndroidConfig) - DESKTOP_ONLY
assert missing == set()
+
+
+def signaturesOf(module) -> dict[str, inspect.Signature]:
+ return {
+ name: inspect.signature(value)
+ for name, value in vars(module).items()
+ if inspect.isfunction(value) and value.__module__ == module.__name__ and not name.startswith("_")
+ }
+
+
+def test_android_cfg_functions_match_desktop_signatures():
+ desktop, android = signaturesOf(desktopCfg), signaturesOf(loadAndroidCfg())
+ mismatched = {name for name in desktop.keys() & android.keys() if desktop[name] != android[name]}
+ assert mismatched == set()