Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index/src/pixelrag_index/sources/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def __init__(
if p.exists():
with open(p, encoding="utf-8") as f:
self._urls = [
line.strip()
cleaned
for line in f
if line.strip() and not line.startswith("#")
if (cleaned := line.strip()) and not cleaned.startswith("#")
]
else:
raise FileNotFoundError(f"urls_file not found: {urls_file}")
Expand Down
34 changes: 34 additions & 0 deletions tests/test_web_source_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Regression tests for WebSource URL file parsing."""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parents[1] / "index" / "src"))

from pixelrag_index.sources.web import WebSource


def _write(tmp_path, content):
p = tmp_path / "urls.txt"
p.write_text(content, encoding="utf-8")
return WebSource(urls_file=str(p))


def test_plain_urls_are_kept(tmp_path):
src = _write(tmp_path, "https://a.com\nhttps://b.com\n")
assert src._urls == ["https://a.com", "https://b.com"]


def test_indented_comment_lines_are_skipped(tmp_path):
src = _write(tmp_path, "https://a.com\n # indented comment\n\thttps://b.com\n")
assert src._urls == ["https://a.com", "https://b.com"]


def test_blank_and_full_comment_lines_are_skipped(tmp_path):
src = _write(tmp_path, "# top comment\n\nhttps://a.com\n \n# another\n")
assert src._urls == ["https://a.com"]


def test_surrounding_whitespace_is_stripped(tmp_path):
src = _write(tmp_path, " https://a.com \n")
assert src._urls == ["https://a.com"]
Loading