Format server code with ruff recommendations

This commit is contained in:
Debanjum
2025-08-01 00:10:34 -07:00
parent 4a3ed9e5a4
commit c8e07e86e4
65 changed files with 407 additions and 370 deletions

View File

@@ -8,7 +8,7 @@ from khoj.processor.content.markdown.markdown_to_entries import MarkdownToEntrie
def test_extract_markdown_with_no_headings(tmp_path):
"Convert markdown file with no heading to entry format."
# Arrange
entry = f"""
entry = """
- Bullet point 1
- Bullet point 2
"""
@@ -35,7 +35,7 @@ def test_extract_markdown_with_no_headings(tmp_path):
def test_extract_single_markdown_entry(tmp_path):
"Convert markdown from single file to entry format."
# Arrange
entry = f"""### Heading
entry = """### Heading
\t\r
Body Line 1
"""
@@ -55,7 +55,7 @@ def test_extract_single_markdown_entry(tmp_path):
def test_extract_multiple_markdown_entries(tmp_path):
"Convert multiple markdown from single file to entry format."
# Arrange
entry = f"""
entry = """
### Heading 1
\t\r
Heading 1 Body Line 1
@@ -81,7 +81,7 @@ def test_extract_multiple_markdown_entries(tmp_path):
def test_extract_entries_with_different_level_headings(tmp_path):
"Extract markdown entries with different level headings."
# Arrange
entry = f"""
entry = """
# Heading 1
## Sub-Heading 1.1
# Heading 2
@@ -104,7 +104,7 @@ def test_extract_entries_with_different_level_headings(tmp_path):
def test_extract_entries_with_non_incremental_heading_levels(tmp_path):
"Extract markdown entries when deeper child level before shallower child level."
# Arrange
entry = f"""
entry = """
# Heading 1
#### Sub-Heading 1.1
## Sub-Heading 1.2
@@ -129,7 +129,7 @@ def test_extract_entries_with_non_incremental_heading_levels(tmp_path):
def test_extract_entries_with_text_before_headings(tmp_path):
"Extract markdown entries with some text before any headings."
# Arrange
entry = f"""
entry = """
Text before headings
# Heading 1
body line 1
@@ -149,15 +149,15 @@ body line 2
assert len(entries[1]) == 3
assert entries[1][0].raw == "\nText before headings"
assert entries[1][1].raw == "# Heading 1\nbody line 1"
assert (
entries[1][2].raw == "# Heading 1\n## Heading 2\nbody line 2\n"
), "Ensure raw entry includes heading ancestory"
assert entries[1][2].raw == "# Heading 1\n## Heading 2\nbody line 2\n", (
"Ensure raw entry includes heading ancestory"
)
def test_parse_markdown_file_into_single_entry_if_small(tmp_path):
"Parse markdown file into single entry if it fits within the token limits."
# Arrange
entry = f"""
entry = """
# Heading 1
body line 1
## Subheading 1.1
@@ -180,7 +180,7 @@ body line 1.1
def test_parse_markdown_entry_with_children_as_single_entry_if_small(tmp_path):
"Parse markdown entry with child headings as single entry if it fits within the tokens limits."
# Arrange
entry = f"""
entry = """
# Heading 1
body line 1
## Subheading 1.1
@@ -201,13 +201,13 @@ longer body line 2.1
# Assert
assert len(entries) == 2
assert len(entries[1]) == 3
assert (
entries[1][0].raw == "# Heading 1\nbody line 1\n## Subheading 1.1\nbody line 1.1"
), "First entry includes children headings"
assert entries[1][0].raw == "# Heading 1\nbody line 1\n## Subheading 1.1\nbody line 1.1", (
"First entry includes children headings"
)
assert entries[1][1].raw == "# Heading 2\nbody line 2", "Second entry does not include children headings"
assert (
entries[1][2].raw == "# Heading 2\n## Subheading 2.1\nlonger body line 2.1\n"
), "Third entry is second entries child heading"
assert entries[1][2].raw == "# Heading 2\n## Subheading 2.1\nlonger body line 2.1\n", (
"Third entry is second entries child heading"
)
def test_line_number_tracking_in_recursive_split():
@@ -252,14 +252,16 @@ def test_line_number_tracking_in_recursive_split():
assert entry.uri is not None, f"Entry '{entry}' has a None URI."
assert match is not None, f"URI format is incorrect: {entry.uri}"
assert (
filepath_from_uri == markdown_file_path
), f"File path in URI '{filepath_from_uri}' does not match expected '{markdown_file_path}'"
assert filepath_from_uri == markdown_file_path, (
f"File path in URI '{filepath_from_uri}' does not match expected '{markdown_file_path}'"
)
# Ensure the first non-heading line in the compiled entry matches the line in the file
assert (
cleaned_first_entry_line in line_in_file.strip() or cleaned_first_entry_line in next_line_in_file.strip()
), f"First non-heading line '{cleaned_first_entry_line}' in {entry.raw} does not match line {line_number_from_uri} in file: '{line_in_file}' or next line '{next_line_in_file}'"
), (
f"First non-heading line '{cleaned_first_entry_line}' in {entry.raw} does not match line {line_number_from_uri} in file: '{line_in_file}' or next line '{next_line_in_file}'"
)
# Helper Functions