45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""测试夹具:加载从真实站点抓取并裁剪后的页面状态样本"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
FIXTURES_DIR = Path(__file__).parent / "fixtures"
|
|
|
|
|
|
def load_fixture(name: str) -> dict[str, Any]:
|
|
return json.loads((FIXTURES_DIR / name).read_text(encoding="utf-8"))
|
|
|
|
|
|
@pytest.fixture
|
|
def search_state() -> dict[str, Any]:
|
|
"""搜索页 __INITIAL_STATE__ 样本(保留 1 条广告位 + 2 条普通商品)"""
|
|
return load_fixture("search_state.json")
|
|
|
|
|
|
@pytest.fixture
|
|
def item_state() -> dict[str, Any]:
|
|
"""商品详情页 __INITIAL_STATE__ 样本(多 SKU 商品,variants 裁剪为 3 条)"""
|
|
return load_fixture("item_state.json")
|
|
|
|
|
|
@pytest.fixture
|
|
def item_with_options_state() -> dict[str, Any]:
|
|
"""带商品选项(名入れギフト)的详情页样本,含必填 select 与自由文本 text"""
|
|
return load_fixture("item_with_options_state.json")
|
|
|
|
|
|
@pytest.fixture
|
|
def genre_root_state() -> dict[str, Any]:
|
|
"""哨兵关键词搜索页样本,根节点挂着全部顶层分类"""
|
|
return load_fixture("genre_root_state.json")
|
|
|
|
|
|
@pytest.fixture
|
|
def genre_node_state() -> dict[str, Any]:
|
|
"""分类页样本(テレビゲーム 101205,顶层分类,带 genreInfo)"""
|
|
return load_fixture("genre_node_state.json")
|