Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

Add edge case tests for document loaders (multi-doc YAML, anchors, BOM, duplicates)

LearningCircuit97ac1296b9c1
diff --git a/tests/document_loaders/test_bytes_loader.py b/tests/document_loaders/test_bytes_loader.py
index b8761d6f5e..658eee184e 100644
--- a/tests/document_loaders/test_bytes_loader.py
+++ b/tests/document_loaders/test_bytes_loader.py
@@ -171,6 +171,23 @@ class TestExtractTextFromBytes:
# Should be string (joined if multiple docs)
assert isinstance(result, str)
+ def test_extract_whitespace_only_txt(self) -> None:
+ """Whitespace-only TXT files should return whitespace or empty string."""
+ content = b" \n\t\n "
+ result = extract_text_from_bytes(content, ".txt", "whitespace.txt")
+
+ # Should not raise, result may be whitespace or empty
+ assert result is not None or result == ""
+
+ def test_extract_json_with_utf8_bom(self) -> None:
+ """Handle UTF-8 BOM (Byte Order Mark) prefix in JSON."""
+ # UTF-8 BOM: \xef\xbb\xbf
+ content = b'\xef\xbb\xbf{"name": "test"}'
+ result = extract_text_from_bytes(content, ".json", "bom.json")
+
+ assert result is not None
+ assert "test" in result
+
class TestTempFileCleanup:
"""Tests for temporary file cleanup."""
diff --git a/tests/document_loaders/test_json_loader.py b/tests/document_loaders/test_json_loader.py
index a05d6ed501..4ae594ec07 100644
--- a/tests/document_loaders/test_json_loader.py
+++ b/tests/document_loaders/test_json_loader.py
@@ -210,6 +210,18 @@ class TestSimpleJSONLoader:
with pytest.raises(Exception):
loader.load()
+ def test_load_json_with_duplicate_keys(self, tmp_path: Path) -> None:
+ """JSON with duplicate keys - last value wins per RFC 8259."""
+ json_file = tmp_path / "duplicates.json"
+ json_file.write_text('{"key": "first", "key": "second"}')
+
+ loader = SimpleJSONLoader(json_file)
+ docs = loader.load()
+
+ assert len(docs) == 1
+ # Python's json.loads keeps last value for duplicate keys
+ assert "second" in docs[0].page_content
+
class TestExtractTextFromJson:
"""Tests for extract_text_from_json function."""
diff --git a/tests/document_loaders/test_yaml_loader.py b/tests/document_loaders/test_yaml_loader.py
index 214d870af4..9fa30ee4c1 100644
--- a/tests/document_loaders/test_yaml_loader.py
+++ b/tests/document_loaders/test_yaml_loader.py
@@ -127,6 +127,37 @@ fruits:
with pytest.raises(Exception):
loader.load()
+ def test_load_multi_document_yaml(self, tmp_path: Path) -> None:
+ """YAML files can contain multiple documents separated by ---"""
+ yaml_file = tmp_path / "multi.yaml"
+ yaml_file.write_text("name: doc1\n---\nname: doc2")
+
+ loader = YAMLLoader(yaml_file)
+ docs = loader.load()
+
+ # Should load first document (PyYAML safe_load behavior)
+ assert len(docs) >= 1
+ assert "doc1" in docs[0].page_content
+
+ def test_load_yaml_with_anchors(self, tmp_path: Path) -> None:
+ """YAML supports &anchor and *alias references."""
+ yaml_content = """defaults: &defaults
+ timeout: 30
+production:
+ <<: *defaults
+ host: prod.example.com
+"""
+ yaml_file = tmp_path / "anchors.yaml"
+ yaml_file.write_text(yaml_content)
+
+ loader = YAMLLoader(yaml_file)
+ docs = loader.load()
+
+ assert len(docs) == 1
+ # Anchors should be resolved - production should have timeout from defaults
+ assert "timeout" in docs[0].page_content
+ assert "30" in docs[0].page_content
+
class TestExtractTextFromYaml:
"""Tests for extract_text_from_yaml function."""