Files
Assaf Elovic f29f3e182e fix(scrapers): guard null sessions, null content, and partial payloads
Consolidates 10 single-file PRs from @Bartok9.

Scrapers assumed a live session and well-formed responses: a None
session raised instead of falling back, None content hit len() before
any check, TavilyExtract indexed keys the API omits on partial results,
and image/dimension parsing assumed str where BeautifulSoup can return
a list or None.

Squashed from #1915 #1916 #1939 #1948 #1949 #1965 #1990 #1991 #2004 #2005.

Two of the tests needed repair before they could be kept. Both stubbed
bs4 via setdefault() and then unconditionally assigned
sys.modules['bs4'].BeautifulSoup = MagicMock -- setdefault returns the
real module when bs4 is already imported, so the real BeautifulSoup
became a MagicMock process-wide and test_scraper_extract_title failed
once both were collected together. They now stub only when bs4 is
genuinely absent. Several also left gpt_researcher stubs in sys.modules
permanently, breaking collection for every module after them; those now
snapshot and restore.

Co-Authored-By: Bartok9 <noreply@github.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-23 12:03:40 +03:00

26 lines
710 B
Python

"""parse_dimension must tolerate None/non-str width/height attrs."""
from __future__ import annotations
import importlib.util
from pathlib import Path
def _load():
path = Path(__file__).resolve().parents[1] / "gpt_researcher" / "scraper" / "utils.py"
spec = importlib.util.spec_from_file_location("scraper_utils_ut", path)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
def test_parse_dimension_none():
u = _load()
assert u.parse_dimension(None) is None
def test_parse_dimension_px_and_int():
u = _load()
assert u.parse_dimension("100px") == 100
assert u.parse_dimension(80) == 80
assert u.parse_dimension("auto") is None