test(#1749): selector 落点断言改 overlap 语义 + cover 路由枚举适配新版 fastapi _IncludedRouter
- test_variant_plan_selector_1743:0.25s 窗口扫描落点不固定,断言改为重叠语义(≤2s/10s 段) - test_generation_cover:递归 original_router 收集路径(新版 fastapi 延迟包装无 .path/.routes)
This commit is contained in:
@@ -57,19 +57,29 @@ def test_templates_editor_no_cover_router():
|
||||
assert "generate-cover" not in getattr(route, "path", ""), "templates_editor 不应再有 generate-cover 路由"
|
||||
|
||||
|
||||
def _collect_route_paths(route, acc):
|
||||
"""递归收集路由路径(兼容新版 fastapi 的 _IncludedRouter 延迟包装)。"""
|
||||
path = getattr(route, "path", None)
|
||||
if isinstance(path, str):
|
||||
acc.append(path)
|
||||
# 新版 fastapi:_IncludedRouter.original_router;旧版:嵌套 .routes
|
||||
inner = getattr(route, "original_router", None)
|
||||
if inner is not None and hasattr(inner, "routes"):
|
||||
for sub in inner.routes:
|
||||
_collect_route_paths(sub, acc)
|
||||
sub_routes = getattr(route, "routes", None)
|
||||
if sub_routes:
|
||||
for sub in sub_routes:
|
||||
_collect_route_paths(sub, acc)
|
||||
|
||||
|
||||
def test_api_router_has_generation_cover():
|
||||
"""api_router 应该包含 /api/v1/generation/generate-cover 路径"""
|
||||
from app.api.router import api_router
|
||||
|
||||
all_paths = []
|
||||
all_paths: list[str] = []
|
||||
for route in api_router.routes:
|
||||
if hasattr(route, "path"):
|
||||
all_paths.append(route.path)
|
||||
# 嵌套 router
|
||||
if hasattr(route, "routes"):
|
||||
for sub_route in route.routes:
|
||||
if hasattr(sub_route, "path"):
|
||||
all_paths.append(sub_route.path)
|
||||
_collect_route_paths(route, all_paths)
|
||||
|
||||
# 应该能找到 generate-cover 路径
|
||||
cover_paths = [p for p in all_paths if "generate-cover" in p]
|
||||
|
||||
@@ -235,9 +235,15 @@ class TestBatchOverlapAvoidance:
|
||||
|
||||
main = [c for c in clips if c["clip_type"] == "main"]
|
||||
assert len(main) == 1
|
||||
ratio = _clip_overlap_ratio("a1", main[0]["start_time"], 10.0, {"a1": [(0.0, 100.0)]})
|
||||
start = main[0]["start_time"]
|
||||
ratio = _clip_overlap_ratio("a1", start, 10.0, {"a1": [(0.0, 100.0)]})
|
||||
assert ratio <= BATCH_CLIP_OVERLAP_LIMIT, f"避让后重叠应 ≤20%,实际 {ratio:.2%}"
|
||||
assert main[0]["start_time"] == pytest.approx(105.0, abs=0.01)
|
||||
# #1749:选片改 0.25s 窗口扫描找最优错开起点(不再依赖 rng.uniform 单点),
|
||||
# 落点只需满足语义:与已用区间 [0,100) 不完全重叠且重叠 ≤20%
|
||||
assert start > 0.0
|
||||
# start+10 区间与 [0,100) 的重叠段(若有)≤ 2s
|
||||
overlap = max(0.0, min(start + 10.0, 100.0) - max(start, 0.0))
|
||||
assert overlap <= 2.0 + 1e-6, f"重叠时长 {overlap}s 应 ≤2s(10s 段的 20%)"
|
||||
|
||||
def test_first_variant_segments_become_avoidance_target(self):
|
||||
"""变体 0 选定区间后,变体 1 选同素材时批次区间生效(不与源区间完全重合)。"""
|
||||
|
||||
Reference in New Issue
Block a user