forked from masonhuang/cluster4npu
- Add .autoflow/ with health check, PRD, Design Doc, TDD, progress tracking - Add tests/conftest.py with PyQt5/KP SDK stubs for unit testing - Add pytest config to pyproject.toml (pythonpath, import-mode, test naming) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
"""
|
||
tests/conftest.py — 單元測試環境設定。
|
||
|
||
此 conftest.py 位於 tests/ 目錄(非 Python 套件),
|
||
可在 root __init__.py 被觸發前完成 Mock 注入。
|
||
|
||
在沒有 Kneron NPU 硬體、PyQt5、NodeGraphQt 的環境下,
|
||
仍可測試 core/performance/ 的純 Python 邏輯。
|
||
"""
|
||
import sys
|
||
from unittest.mock import MagicMock
|
||
|
||
|
||
def _install_mock(name: str) -> None:
|
||
"""若模組尚未存在,安裝空 MagicMock 作為替代。"""
|
||
if name not in sys.modules:
|
||
sys.modules[name] = MagicMock()
|
||
|
||
|
||
# Kneron KP SDK(需要硬體驅動程式)
|
||
_install_mock("kp")
|
||
|
||
# NumPy(可能未安裝)
|
||
try:
|
||
import numpy # noqa: F401
|
||
except ImportError:
|
||
_install_mock("numpy")
|
||
|
||
# PyQt5 相關模組(需要 GUI 環境)
|
||
for _mod in [
|
||
"PyQt5",
|
||
"PyQt5.QtWidgets",
|
||
"PyQt5.QtCore",
|
||
"PyQt5.QtGui",
|
||
"PyQt5.QtChart",
|
||
]:
|
||
_install_mock(_mod)
|
||
|
||
# NodeGraphQt(依賴 PyQt5)
|
||
_install_mock("NodeGraphQt")
|
||
_install_mock("NodeGraphQt.constants")
|
||
_install_mock("NodeGraphQt.base")
|
||
_install_mock("NodeGraphQt.base.node")
|
||
|
||
# OpenCV(可能未安裝)
|
||
_install_mock("cv2")
|