归档 legacy/:stereo_yolo/stereo_ranger/target_tracker 三包 + 175 条测试 + demo/配置/权重/三份规格;运行链路不再依赖,默认 pytest 446 条,归档测试按需运行。 目标有效性第二判据改为 LOS 运动学一致性(pod_bridge/los_consistency.py),删除 require_vision;pod_locked() 叠加该判据,状态机随之后退重搜。 自定义返航(task_runner/return_home.py):保持转场高度回起飞点 → 恢复初始航向 → 垂直降落,不再爬 RTL_RETURN_ALT;未起飞/无起飞点/超时/异常仍退回 PX4 原生 RTL。 任务链安全兜底:主循环异常→紧急返航、stop 幂等、landing_stop 保留遥测、in_air 流复用+超时、解锁/起飞与吊舱识别仅执行一次、rtl_timeout 上限。 入口共享件拆到 utils/sitl_support.py;pod_sitl_test.py→l1_sitl_test.py;删除旧架构 test.py;相机脚本移入 tools/。 新增 .gitignore 并剔除历史误跟踪的 59 个 .pyc;requirements 按实际依赖重写;文档全面对齐,新增 legacy/README.md 与 tools/README.md。
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""告警节流测试(规格 §5:第 1 次 + 每满 100 次,带累计计数)。"""
|
|
|
|
import pytest
|
|
|
|
from stereo_ranger import WarnThrottle
|
|
|
|
|
|
def test_first_and_every_hundred_emit():
|
|
throttle = WarnThrottle() # 默认 every=100
|
|
assert throttle.should_emit("a") is True
|
|
for _ in range(98):
|
|
assert throttle.should_emit("a") is False
|
|
assert throttle.should_emit("a") is True # 第 100 次
|
|
for _ in range(99):
|
|
assert throttle.should_emit("a") is False
|
|
assert throttle.should_emit("a") is True # 第 200 次
|
|
assert throttle.count("a") == 200
|
|
|
|
|
|
def test_categories_are_independent():
|
|
throttle = WarnThrottle()
|
|
assert throttle.should_emit("a") is True
|
|
assert throttle.should_emit("b") is True
|
|
assert throttle.count("a") == 1
|
|
assert throttle.count("b") == 1
|
|
assert throttle.count("never_seen") == 0
|
|
|
|
|
|
def test_custom_interval():
|
|
throttle = WarnThrottle(every=3)
|
|
# 规格语义"第 1 次 + 计数每满 every" → 第 1/3/6 次打印
|
|
assert [throttle.should_emit("a") for _ in range(6)] == [True, False, True, False, False, True]
|
|
|
|
|
|
def test_clear_resets_counts():
|
|
throttle = WarnThrottle()
|
|
throttle.should_emit("a")
|
|
throttle.clear()
|
|
assert throttle.count("a") == 0
|
|
assert throttle.should_emit("a") is True
|
|
|
|
|
|
def test_invalid_interval():
|
|
with pytest.raises(ValueError):
|
|
WarnThrottle(every=0)
|