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
237 lines
7.3 KiB
Python
237 lines
7.3 KiB
Python
"""
|
||
Deep coverage tests for loader_registry module.
|
||
|
||
Targets branches and code paths not exercised by the existing
|
||
test_loader_registry_coverage.py file:
|
||
- get_loader_for_path with extension-without-dot normalisation
|
||
- get_loader_class_for_extension with extension-without-dot path
|
||
- JSON / YAML kwargs correctness
|
||
- ipynb and enex kwargs
|
||
- registry completeness for always-present extensions
|
||
- is_extension_supported with dot-prefixed input
|
||
"""
|
||
|
||
from unittest.mock import patch
|
||
|
||
import pytest
|
||
|
||
MODULE = "local_deep_research.document_loaders.loader_registry"
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# get_loader_class_for_extension – branch: no-dot input path
|
||
# ---------------------------------------------------------------------------
|
||
|
||
|
||
class TestGetLoaderClassForExtensionNoDot:
|
||
"""Exercise the branch where extension does NOT start with a dot."""
|
||
|
||
def test_txt_without_dot_resolves(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
get_loader_class_for_extension,
|
||
)
|
||
|
||
result = get_loader_class_for_extension("txt")
|
||
assert result is not None
|
||
loader_class, kwargs = result
|
||
assert loader_class.__name__ == "TextLoader"
|
||
|
||
def test_pdf_without_dot_resolves(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
get_loader_class_for_extension,
|
||
)
|
||
|
||
result = get_loader_class_for_extension("pdf")
|
||
assert result is not None
|
||
assert result[0].__name__ == "PyPDFLoader"
|
||
|
||
def test_json_without_dot_resolves(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
get_loader_class_for_extension,
|
||
)
|
||
|
||
result = get_loader_class_for_extension("json")
|
||
assert result is not None
|
||
assert result[0].__name__ == "SimpleJSONLoader"
|
||
|
||
def test_unknown_without_dot_returns_none(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
get_loader_class_for_extension,
|
||
)
|
||
|
||
assert get_loader_class_for_extension("zzz_unknown") is None
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# is_extension_supported – branch: no-dot input path
|
||
# ---------------------------------------------------------------------------
|
||
|
||
|
||
class TestIsExtensionSupportedNoDotBranch:
|
||
"""Exercise the branch that prepends a dot when missing."""
|
||
|
||
def test_csv_without_dot(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
is_extension_supported,
|
||
)
|
||
|
||
assert is_extension_supported("csv") is True
|
||
|
||
def test_md_without_dot_uppercase(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
is_extension_supported,
|
||
)
|
||
|
||
assert is_extension_supported("MD") is True
|
||
|
||
def test_unknown_without_dot(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
is_extension_supported,
|
||
)
|
||
|
||
assert is_extension_supported("zzz") is False
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# get_loader_for_path – loader constructor exception path
|
||
# ---------------------------------------------------------------------------
|
||
|
||
|
||
class TestGetLoaderForPathExceptionHandling:
|
||
"""Verify that get_loader_for_path returns None when the loader raises."""
|
||
|
||
def test_constructor_runtime_error_returns_none(self, tmp_path):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
LOADER_REGISTRY,
|
||
get_loader_for_path,
|
||
)
|
||
|
||
class _BrokenLoader:
|
||
def __init__(self, *args, **kwargs):
|
||
raise RuntimeError("constructor broken")
|
||
|
||
f = tmp_path / "test.toml"
|
||
f.write_text("[key]\nvalue = 1")
|
||
|
||
with patch.dict(
|
||
LOADER_REGISTRY,
|
||
{".toml": {"loader_class": _BrokenLoader, "loader_kwargs": {}}},
|
||
):
|
||
result = get_loader_for_path(f)
|
||
assert result is None
|
||
|
||
def test_constructor_value_error_returns_none(self, tmp_path):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
LOADER_REGISTRY,
|
||
get_loader_for_path,
|
||
)
|
||
|
||
class _ValErrLoader:
|
||
def __init__(self, *args, **kwargs):
|
||
raise ValueError("bad value")
|
||
|
||
f = tmp_path / "sample.eml"
|
||
f.write_text("From: a@b.com\n\nHello")
|
||
|
||
with patch.dict(
|
||
LOADER_REGISTRY,
|
||
{".eml": {"loader_class": _ValErrLoader, "loader_kwargs": {}}},
|
||
):
|
||
result = get_loader_for_path(f)
|
||
assert result is None
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# Always-present extensions
|
||
# ---------------------------------------------------------------------------
|
||
|
||
|
||
class TestAlwaysPresentExtensions:
|
||
"""Verify extensions that must exist regardless of optional loader flags."""
|
||
|
||
@pytest.mark.parametrize(
|
||
"ext",
|
||
[
|
||
".pdf",
|
||
".txt",
|
||
".md",
|
||
".markdown",
|
||
".docx",
|
||
".csv",
|
||
".xlsx",
|
||
".xls",
|
||
".html",
|
||
".htm",
|
||
".pptx",
|
||
".xml",
|
||
".eml",
|
||
".tsv",
|
||
".json",
|
||
".yaml",
|
||
".yml",
|
||
".ipynb",
|
||
".enex",
|
||
".toml",
|
||
".mhtml",
|
||
".mht",
|
||
],
|
||
)
|
||
def test_extension_always_registered(self, ext):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
LOADER_REGISTRY,
|
||
)
|
||
|
||
assert ext in LOADER_REGISTRY, f"{ext} not in LOADER_REGISTRY"
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# Kwargs deep checks
|
||
# ---------------------------------------------------------------------------
|
||
|
||
|
||
class TestSpecificKwargsDeep:
|
||
"""Deeper checks on loader kwargs not covered by existing tests."""
|
||
|
||
def test_json_loader_kwargs_empty(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
LOADER_REGISTRY,
|
||
)
|
||
|
||
assert LOADER_REGISTRY[".json"]["loader_kwargs"] == {}
|
||
|
||
def test_yaml_loader_kwargs_empty(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
LOADER_REGISTRY,
|
||
)
|
||
|
||
assert LOADER_REGISTRY[".yaml"]["loader_kwargs"] == {}
|
||
|
||
def test_yml_loader_kwargs_empty(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
LOADER_REGISTRY,
|
||
)
|
||
|
||
assert LOADER_REGISTRY[".yml"]["loader_kwargs"] == {}
|
||
|
||
def test_enex_single_document_false(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
LOADER_REGISTRY,
|
||
)
|
||
|
||
entry = LOADER_REGISTRY[".enex"]
|
||
assert entry["loader_kwargs"].get("load_single_document") is False
|
||
|
||
def test_mhtml_kwargs_empty(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
LOADER_REGISTRY,
|
||
)
|
||
|
||
assert LOADER_REGISTRY[".mhtml"]["loader_kwargs"] == {}
|
||
|
||
def test_mht_kwargs_empty(self):
|
||
from local_deep_research.document_loaders.loader_registry import (
|
||
LOADER_REGISTRY,
|
||
)
|
||
|
||
assert LOADER_REGISTRY[".mht"]["loader_kwargs"] == {}
|