Skip to content

Add comprehensive tests for LocalRepoLoader and UrlRepoLoader #30

Description

@vineet1cg

Description

The two core loader classes (LocalRepoLoader and UrlRepoLoader) in repo2readme/loaders/loader.py have zero test coverage. These are critical components — they handle all repository file loading and filtering logic. Any regression here breaks the entire tool.

Files

  • repo2readme/loaders/loader.py (full file, 144 lines)
  • tests/test_loader.py (needs to be created)

What Needs Testing

LocalRepoLoader

  1. __init__: Verify parameters are stored correctly
  2. _should_include: Test with include/exclude patterns, max file size
  3. load():
    • Loads files from a temp directory
    • Correct metadata fields (file_path, file_name, file_type, relative_path)
    • Skips files exceeding max_file_size_kb
    • Filters directories via os.walk dirs[:] mutation
    • Raises FileNotFoundError for invalid path
    • Handles unreadable files gracefully (logs error, continues)

UrlRepoLoader

  1. __init__: Verify parameters stored correctly
  2. get_repo_name: Extract name from various URL formats
  3. _should_include: Filter logic similar to LocalRepoLoader
  4. load():
    • Git clone via GitLoader
    • Metadata correctness for loaded docs
    • Temp directory creation/cleanup
  5. cleanup(): Removes temp directory

Example Test Skeleton

import pytest
from pathlib import Path
from repo2readme.loaders.loader import LocalRepoLoader

def test_local_loader_loads_files(tmp_path):
    # Create test files
    main_py = tmp_path / "main.py"
    main_py.write_text("print(hello)")
    
    loader = LocalRepoLoader(str(tmp_path))
    docs, root_path = loader.load()
    
    assert len(docs) == 1
    assert docs[0].metadata["file_name"] == "main.py"
    assert docs[0].metadata["file_type"] == ".py"
    assert root_path == str(tmp_path)

def test_local_loader_filters_by_size(tmp_path):
    large_file = tmp_path / "large.bin"
    large_file.write_text("x" * 300 * 1024)
    
    loader = LocalRepoLoader(str(tmp_path), max_file_size_kb=200)
    docs, _ = loader.load()
    assert len(docs) == 0  # Should skip oversized file

Difficulty

Easy - Straightforward use of pytest + tmp_path fixtures, no mocking of LLMs required.

Impact

  • Catches regressions in the file loading pipeline
  • Ensures filter correctness (include/exclude patterns, file size limits)
  • Prevents bugs in metadata propagation to the summarization stage
  • Improves overall test coverage from ~25% to ~40%

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions