mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-14 14:17:08 +00:00
More tests
This commit is contained in:
1 parent
d5c0322e2a
commit
a3b08a5b44
37 files changed
+21904
-6
No files matched your search
@@ -56,3 +56,52 @@ class TestBaseDocument:
|
||||
def test_extra_info_str_none(self):
|
||||
doc = ConcreteDoc(text="x")
|
||||
assert doc.extra_info_str is None
|
||||
|
||||
|
||||
# =====================================================================
|
||||
# Coverage gap tests for application/parser/schema/base.py (lines 19, 27, 34)
|
||||
# =====================================================================
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class TestDocumentBase:
|
||||
|
||||
def test_document_post_init_raises_on_none_text(self):
|
||||
"""Cover line 19: Document.__post_init__ raises ValueError for None text."""
|
||||
from application.parser.schema.base import Document
|
||||
|
||||
with pytest.raises(ValueError, match="text field not set"):
|
||||
Document(text=None)
|
||||
|
||||
def test_document_to_langchain_format(self):
|
||||
"""Cover line 27: Document.to_langchain_format converts correctly."""
|
||||
from application.parser.schema.base import Document
|
||||
|
||||
doc = Document(text="hello world", extra_info={"source": "test"})
|
||||
lc_doc = doc.to_langchain_format()
|
||||
assert lc_doc.page_content == "hello world"
|
||||
assert lc_doc.metadata == {"source": "test"}
|
||||
|
||||
def test_document_to_langchain_format_no_extra_info(self):
|
||||
"""Cover: to_langchain_format with no extra_info uses empty dict."""
|
||||
from application.parser.schema.base import Document
|
||||
|
||||
doc = Document(text="hello")
|
||||
lc_doc = doc.to_langchain_format()
|
||||
assert lc_doc.metadata == {}
|
||||
|
||||
def test_document_from_langchain_format(self):
|
||||
"""Cover line 34: Document.from_langchain_format creates Document."""
|
||||
from application.parser.schema.base import Document
|
||||
from langchain_core.documents import Document as LCDocument
|
||||
|
||||
lc_doc = LCDocument(page_content="test content", metadata={"key": "val"})
|
||||
doc = Document.from_langchain_format(lc_doc)
|
||||
assert doc.text == "test content"
|
||||
assert doc.extra_info == {"key": "val"}
|
||||
|
||||
def test_document_get_type(self):
|
||||
"""Cover line 24: Document.get_type returns 'Document'."""
|
||||
from application.parser.schema.base import Document
|
||||
|
||||
assert Document.get_type() == "Document"
|
||||
Reference in new issue
Block a user