#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ test_all_apis.py - 测试 ap_ds 文档中所有 API 是否存在 包括 AudioLibrary 类的所有方法 """ import sys import inspect print("=" * 60) print("🧪 Testing All ap_ds API Exports") print("=" * 60) # ============================================================ # 1. 测试顶级函数导入 # ============================================================ TOP_LEVEL_APIS = [ "AudioLibrary", "batch_get_metadata", "batch_get_duration", "batch_get_metadata_by_type", "get_audio_duration", "get_audio_metadata", "auto_check_runtime", "check_runtime_mode", "show_tech_manual", ] print("\n📦 Testing top-level imports:") print("-" * 40) passed = 0 failed = 0 missing = [] for name in TOP_LEVEL_APIS: try: exec(f"from ap_ds import {name}") print(f" ✅ {name}") passed += 1 except ImportError as e: print(f" ❌ {name}: {e}") failed += 1 missing.append(name) # ============================================================ # 2. 测试 AudioLibrary 类的所有方法 # ============================================================ AUDIOLIBRARY_METHODS = [ # 初始化 "__init__", # 播放方法 "play_from_file", "play_from_memory", "new_aid", # 控制方法 "play_audio", "pause_audio", "stop_audio", "seek_audio", # 音量方法 "set_volume", "get_volume", # 淡入淡出与过渡方法 "fadein_music", "fadein_music_pos", "fadeout_music", "is_music_playing", "is_music_paused", "get_music_fading", # 元数据方法 "get_audio_duration", "get_audio_metadata", "get_audio_metadata_by_path", "get_audio_metadata_by_aid", # 批量解析方法 "batch_get_metadata", "batch_get_duration", "batch_get_metadata_by_type", # DAP 系统方法 "save_dap_to_json", "get_dap_recordings", "clear_dap_recordings", # 资源管理 "clear_memory_cache", "cleanup_function", # 内部辅助方法 (文档中列出但通常是私有的) "_find_channel_by_aid", "_get_file_path_by_aid", "_is_music_file", "_seek_audio", "_get_duration_by_filepath", "_get_file_duration", ] print("\n" + "-" * 40) print("🎯 Testing AudioLibrary methods:") print("-" * 40) try: from ap_ds import AudioLibrary # 获取 AudioLibrary 类的所有方法 lib_methods = [m for m in dir(AudioLibrary) if not m.startswith('__') or m == '__init__'] for method_name in AUDIOLIBRARY_METHODS: if hasattr(AudioLibrary, method_name): print(f" ✅ AudioLibrary.{method_name}") passed += 1 else: print(f" ❌ AudioLibrary.{method_name} (NOT FOUND)") failed += 1 missing.append(f"AudioLibrary.{method_name}") except ImportError as e: print(f" ❌ Cannot import AudioLibrary: {e}") failed += 1 # ============================================================ # 3. 检查文档中可能遗漏的额外 API # ============================================================ EXTRA_APIS = [ "is_full_performance", "get_runtime_info", ] print("\n" + "-" * 40) print("🔍 Checking extra APIs (mentioned in docs but maybe not exported):") print("-" * 40) for name in EXTRA_APIS: try: exec(f"from ap_ds import {name}") print(f" ✅ {name} (exists!)") passed += 1 except ImportError: print(f" ❌ {name} (NOT FOUND - remove from docs or add to __init__.py)") failed += 1 missing.append(name) # ============================================================ # 4. 汇总 # ============================================================ print("\n" + "=" * 60) print("📊 FINAL SUMMARY") print("=" * 60) if failed == 0: print("🎉 ALL APIs EXIST! Documentation is accurate.") else: print(f"⚠️ {failed} API(s) missing:") for name in missing: print(f" - {name}") print("\n💡 Fix:") print(" Either remove these from documentation, or add them to __init__.py") print("=" * 60) print(f"✅ Passed: {passed}") print(f"❌ Failed: {failed}")