test: stop hardcoding an out-of-repo sys.path in test_protocol.py
tests/test_protocol.py 原本把 "/home/program/NextAgent/src" 硬编码进 sys.path,指向宿主机上另一份(工作区为脏的)NextAgent 检出。结果测试 import 的是那份副本而非本仓库的 src,导致两个用例失败: - test_decode_raises_on_wrong_fmt_id → DecodingError not raised - test_register_and_send → ValueError: inhomogeneous shape 改为基于 __file__ 推导仓库内的 src/ 路径,测试不再依赖仓库外的任何 绝对路径,任何检出位置都能跑通。实现代码未做改动——这是测试耦合问题, 不是实现 bug。 同时取消跟踪 7 个误提交的 .pyc(.gitignore 规则此前加晚了)。 仅 git rm --cached,工作区文件保留;.gitignore 的 __pycache__/ 与 *.pyc 规则继续生效。 python3 -m unittest discover -s tests → Ran 31 tests, OK git ls-files '*.pyc' | wc -l → 0
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,9 +1,11 @@
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
sys.path.insert(0, "/home/program/NextAgent/src")
|
||||
# 仅依赖本仓库布局:tests/ 的上一级的 src/,不引用仓库外任何绝对路径
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))
|
||||
|
||||
from protocol.registry import PROTOCOL_REGISTRY, FMT_NAMES, PARSER_NAMES
|
||||
from protocol.codec import CodecAdapter, IdentityCodec, EncodingError, DecodingError
|
||||
|
||||
Reference in New Issue
Block a user