mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-21 07:26:50 +00:00
refactor(tests): reorganize tests into unittest/ and e2e/ directories
- Move all unit tests from tests/ to tests/unittest/ - Add tests/e2e/ directory for end-to-end tests - Update conftest.py for new test structure - Add new tests for auth dependencies, policies, route injection - Add new tests for run callbacks, create store, execution artifacts - Remove obsolete tests for deleted persistence layer Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"""Tests for readability extraction fallback behavior."""
|
||||
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
from deerflow.utils.readability import ReadabilityExtractor
|
||||
|
||||
|
||||
def test_extract_article_falls_back_when_readability_js_fails(monkeypatch):
|
||||
"""When Node-based readability fails, extraction should fall back to Python mode."""
|
||||
|
||||
calls: list[bool] = []
|
||||
|
||||
def _fake_simple_json_from_html_string(html: str, use_readability: bool = False):
|
||||
calls.append(use_readability)
|
||||
if use_readability:
|
||||
raise subprocess.CalledProcessError(
|
||||
returncode=1,
|
||||
cmd=["node", "ExtractArticle.js"],
|
||||
stderr="boom",
|
||||
)
|
||||
return {"title": "Fallback Title", "content": "<p>Fallback Content</p>"}
|
||||
|
||||
monkeypatch.setattr(
|
||||
"deerflow.utils.readability.simple_json_from_html_string",
|
||||
_fake_simple_json_from_html_string,
|
||||
)
|
||||
|
||||
article = ReadabilityExtractor().extract_article("<html><body>test</body></html>")
|
||||
|
||||
assert calls == [True, False]
|
||||
assert article.title == "Fallback Title"
|
||||
assert article.html_content == "<p>Fallback Content</p>"
|
||||
|
||||
|
||||
def test_extract_article_re_raises_unexpected_exception(monkeypatch):
|
||||
"""Unexpected errors should be surfaced instead of silently falling back."""
|
||||
|
||||
calls: list[bool] = []
|
||||
|
||||
def _fake_simple_json_from_html_string(html: str, use_readability: bool = False):
|
||||
calls.append(use_readability)
|
||||
if use_readability:
|
||||
raise RuntimeError("unexpected parser failure")
|
||||
return {"title": "Should Not Reach Fallback", "content": "<p>Fallback</p>"}
|
||||
|
||||
monkeypatch.setattr(
|
||||
"deerflow.utils.readability.simple_json_from_html_string",
|
||||
_fake_simple_json_from_html_string,
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError, match="unexpected parser failure"):
|
||||
ReadabilityExtractor().extract_article("<html><body>test</body></html>")
|
||||
assert calls == [True]
|
||||
Reference in New Issue
Block a user