-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtest_document.py
More file actions
55 lines (47 loc) · 1.95 KB
/
Copy pathtest_document.py
File metadata and controls
55 lines (47 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
from sqlite_rag.models.document import Document
class TestDocument:
def test_get_title(self):
doc = Document(content="Sample content", metadata={"title": "My Title"})
assert doc.get_title() == "My Title"
def test_get_title_no_title(self):
doc = Document(content="Sample content", metadata={})
assert doc.get_title() is None
def test_set_generated_title(self):
doc = Document(content="This is a test document.", metadata={})
doc.set_generated_title()
assert doc.get_title() == "This is a test document."
def test_extract_document_title_with_heading(self):
content = "# Document Title\nThis is the content."
doc = Document(content=content, metadata={})
assert doc.extract_document_title() == "Document Title"
@pytest.mark.parametrize(
"content,fallback,expected_title",
[
(
"This is the first line.\nThis is the second line.",
True,
"This is the first line.",
),
("\n\nFirst non-empty line.\nAnother line.", True, "First non-empty line."),
(" \n \n Leading spaces line.", True, "Leading spaces line."),
("", True, None),
("\n\n", True, None),
("This is the only line.", False, None),
("\n\n", False, None),
],
)
def test_extract_document_title_without_heading(
self, content, fallback, expected_title
):
doc = Document(content=content, metadata={})
assert (
doc.extract_document_title(fallback_first_line=fallback) == expected_title
)
def test_extract_document_title_with_a_word(self):
content = "---\n \n Leading spaces line with a word."
doc = Document(content=content, metadata={})
assert (
doc.extract_document_title(fallback_first_line=True)
== "Leading spaces line with a word."
)