Files
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

290 lines
9.0 KiB
Python

"""
Behavioral tests for yaml_loader module.
Tests the YAMLLoader and extract_text_from_yaml function.
"""
import tempfile
from pathlib import Path
import yaml
class TestYAMLLoaderInit:
"""Tests for YAMLLoader initialization."""
def test_accepts_string_path(self):
"""Accepts string path."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
loader = YAMLLoader("/path/to/file.yaml")
assert loader.file_path == Path("/path/to/file.yaml")
def test_accepts_path_object(self):
"""Accepts Path object."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
loader = YAMLLoader(Path("/path/to/file.yaml"))
assert loader.file_path == Path("/path/to/file.yaml")
def test_default_encoding_is_utf8(self):
"""Default encoding is utf-8."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
loader = YAMLLoader("/path/to/file.yaml")
assert loader.encoding == "utf-8"
def test_accepts_custom_encoding(self):
"""Accepts custom encoding."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
loader = YAMLLoader("/path/to/file.yaml", encoding="latin-1")
assert loader.encoding == "latin-1"
class TestYAMLLoaderLoad:
"""Tests for YAMLLoader load functionality."""
def test_loads_valid_yaml(self):
"""Loads valid YAML file."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
with tempfile.NamedTemporaryFile(
mode="w", suffix=".yaml", delete=False
) as f:
yaml.dump({"name": "Test", "value": 42}, f)
f.flush()
path = f.name
try:
loader = YAMLLoader(path)
docs = loader.load()
assert len(docs) == 1
assert "name" in docs[0].page_content
assert "Test" in docs[0].page_content
finally:
Path(path).unlink()
def test_includes_source_in_metadata(self):
"""Includes source path in metadata."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
with tempfile.NamedTemporaryFile(
mode="w", suffix=".yaml", delete=False
) as f:
yaml.dump({"key": "value"}, f)
f.flush()
path = f.name
try:
loader = YAMLLoader(path)
docs = loader.load()
assert "source" in docs[0].metadata
assert path in docs[0].metadata["source"]
finally:
Path(path).unlink()
def test_includes_file_type_in_metadata(self):
"""Includes file_type in metadata."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
with tempfile.NamedTemporaryFile(
mode="w", suffix=".yaml", delete=False
) as f:
yaml.dump({"key": "value"}, f)
f.flush()
path = f.name
try:
loader = YAMLLoader(path)
docs = loader.load()
assert docs[0].metadata.get("file_type") == "yaml"
finally:
Path(path).unlink()
def test_handles_invalid_yaml(self):
"""Handles invalid YAML gracefully."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
with tempfile.NamedTemporaryFile(
mode="w", suffix=".yaml", delete=False
) as f:
f.write("invalid: yaml: content:")
f.flush()
path = f.name
try:
loader = YAMLLoader(path)
docs = loader.load()
assert len(docs) == 1
assert docs[0].metadata.get("parse_error") is True
finally:
Path(path).unlink()
def test_skips_empty_yaml(self):
"""Skips empty YAML documents."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
with tempfile.NamedTemporaryFile(
mode="w", suffix=".yaml", delete=False
) as f:
f.write("")
f.flush()
path = f.name
try:
loader = YAMLLoader(path)
docs = loader.load()
assert len(docs) == 0
finally:
Path(path).unlink()
def test_handles_list_yaml(self):
"""Handles YAML with list as root."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
with tempfile.NamedTemporaryFile(
mode="w", suffix=".yaml", delete=False
) as f:
yaml.dump(["item1", "item2", "item3"], f)
f.flush()
path = f.name
try:
loader = YAMLLoader(path)
docs = loader.load()
assert len(docs) == 1
assert "item1" in docs[0].page_content
finally:
Path(path).unlink()
def test_handles_nested_yaml(self):
"""Handles nested YAML structure."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
with tempfile.NamedTemporaryFile(
mode="w", suffix=".yaml", delete=False
) as f:
yaml.dump({"level1": {"level2": {"level3": "deep value"}}}, f)
f.flush()
path = f.name
try:
loader = YAMLLoader(path)
docs = loader.load()
assert len(docs) == 1
assert "level1" in docs[0].page_content
assert "deep value" in docs[0].page_content
finally:
Path(path).unlink()
class TestYAMLLoaderLazyLoad:
"""Tests for YAMLLoader lazy_load functionality."""
def test_lazy_load_yields_documents(self):
"""lazy_load yields Document objects."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
with tempfile.NamedTemporaryFile(
mode="w", suffix=".yaml", delete=False
) as f:
yaml.dump({"key": "value"}, f)
f.flush()
path = f.name
try:
loader = YAMLLoader(path)
docs = list(loader.lazy_load())
assert len(docs) == 1
finally:
Path(path).unlink()
def test_lazy_load_is_iterator(self):
"""lazy_load returns an iterator."""
from local_deep_research.document_loaders.yaml_loader import YAMLLoader
with tempfile.NamedTemporaryFile(
mode="w", suffix=".yaml", delete=False
) as f:
yaml.dump({"key": "value"}, f)
f.flush()
path = f.name
try:
loader = YAMLLoader(path)
result = loader.lazy_load()
# Should be an iterator
assert hasattr(result, "__iter__")
assert hasattr(result, "__next__")
finally:
Path(path).unlink()
class TestExtractTextFromYaml:
"""Tests for extract_text_from_yaml function."""
def test_extracts_text_from_bytes(self):
"""Extracts text from bytes content."""
from local_deep_research.document_loaders.yaml_loader import (
extract_text_from_yaml,
)
content = b"name: John\ncity: NYC"
result = extract_text_from_yaml(content)
assert "name" in result
assert "John" in result
def test_handles_unicode(self):
"""Handles Unicode content."""
from local_deep_research.document_loaders.yaml_loader import (
extract_text_from_yaml,
)
content = "greeting: 你好".encode("utf-8")
result = extract_text_from_yaml(content)
assert "你好" in result
def test_handles_invalid_yaml_bytes(self):
"""Returns raw text for invalid YAML."""
from local_deep_research.document_loaders.yaml_loader import (
extract_text_from_yaml,
)
content = b"invalid: yaml: content:"
result = extract_text_from_yaml(content)
assert "invalid" in result
def test_returns_empty_for_empty_yaml(self):
"""Returns empty string for empty YAML."""
from local_deep_research.document_loaders.yaml_loader import (
extract_text_from_yaml,
)
content = b""
result = extract_text_from_yaml(content)
assert result == ""
def test_uses_custom_encoding(self):
"""Uses custom encoding when specified."""
from local_deep_research.document_loaders.yaml_loader import (
extract_text_from_yaml,
)
# Latin-1 encoded content
content = "text: café".encode("latin-1")
result = extract_text_from_yaml(content, encoding="latin-1")
assert "café" in result
def test_formats_as_block_style(self):
"""Formats output as block-style YAML."""
from local_deep_research.document_loaders.yaml_loader import (
extract_text_from_yaml,
)
content = b"items:\n - one\n - two\n - three"
result = extract_text_from_yaml(content)
# Should have proper block formatting
assert "items:" in result
assert "one" in result