fea(ci): improve prettier config
This commit is contained in:
parent
d4df57bd05
commit
a7eb731730
3 changed files with 64 additions and 4 deletions
43
tests/conftest.py
Normal file
43
tests/conftest.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
FIXTURES = Path(__file__).resolve().parent / "fixtures"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fixture_text():
|
||||
"""Load HTML fixture by filename."""
|
||||
|
||||
def _load(name: str) -> str:
|
||||
p = FIXTURES / name
|
||||
return p.read_text(encoding="utf-8")
|
||||
|
||||
return _load
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def run_scraper(monkeypatch):
|
||||
def _run(name: str, mode: str, *args, replace_fetch=None) -> dict:
|
||||
scraper_path = ROOT / "scrapers" / f"{name}.py"
|
||||
ns = {}
|
||||
code = scraper_path.read_text(encoding="utf-8")
|
||||
if replace_fetch:
|
||||
code = code.replace("def _fetch", "def _fixture_fetch")
|
||||
code += f"\n_fetch = _fixture_fetch\nfetch_text = _fixture_fetch\n"
|
||||
ns.update(replace_fetch)
|
||||
exec(compile(code, str(scraper_path), "exec"), ns)
|
||||
main_async = ns.get("main_async")
|
||||
if not main_async:
|
||||
raise RuntimeError(f"Could not load main_async from {name}.py")
|
||||
import asyncio
|
||||
|
||||
async def wrapper():
|
||||
sys.argv = [str(scraper_path), mode, *args]
|
||||
return await main_async()
|
||||
|
||||
return asyncio.run(wrapper())
|
||||
|
||||
return _run
|
||||
Loading…
Add table
Add a link
Reference in a new issue