test: cover missing-id and non-list roots; drop unreachable empty-nodes guard
This commit is contained in:
@@ -66,8 +66,6 @@ def load_tree_nodes(store_dir: Path, video_id: str) -> dict[str, Any]:
|
|||||||
for root in roots:
|
for root in roots:
|
||||||
_walk(root, 1)
|
_walk(root, 1)
|
||||||
|
|
||||||
if not nodes:
|
|
||||||
raise ValueError(f"展平后 nodes 为空: {tree_path}")
|
|
||||||
return {"nodes": nodes}
|
return {"nodes": nodes}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,24 @@ def test_empty_roots_raises_value_error(tmp_path):
|
|||||||
load_tree_nodes(tmp_path, "vX")
|
load_tree_nodes(tmp_path, "vX")
|
||||||
|
|
||||||
|
|
||||||
|
def test_node_missing_id_raises_value_error(tmp_path):
|
||||||
|
vdir = tmp_path / "videos" / "vX"
|
||||||
|
vdir.mkdir(parents=True)
|
||||||
|
(vdir / "tree.json").write_text(
|
||||||
|
json.dumps({"roots": [{"card": {}, "time_range": [0, 1]}]}), encoding="utf-8"
|
||||||
|
)
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
load_tree_nodes(tmp_path, "vX")
|
||||||
|
|
||||||
|
|
||||||
|
def test_roots_not_list_raises_value_error(tmp_path):
|
||||||
|
vdir = tmp_path / "videos" / "vX"
|
||||||
|
vdir.mkdir(parents=True)
|
||||||
|
(vdir / "tree.json").write_text(json.dumps({"roots": "not-a-list"}), encoding="utf-8")
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
load_tree_nodes(tmp_path, "vX")
|
||||||
|
|
||||||
|
|
||||||
def test_load_for_videos_dedups():
|
def test_load_for_videos_dedups():
|
||||||
data = load_tree_data_for_videos(_STORE, [_VID, _VID])
|
data = load_tree_data_for_videos(_STORE, [_VID, _VID])
|
||||||
assert set(data.keys()) == {_VID}
|
assert set(data.keys()) == {_VID}
|
||||||
|
|||||||
Reference in New Issue
Block a user