Skip to content

feat: add unit tests for LocalRepoLoader and UrlRepoLoader functionality#38

Open
sagar-18-07-2006 wants to merge 2 commits into
agsaru:mainfrom
sagar-18-07-2006:feature/testforurlloader
Open

feat: add unit tests for LocalRepoLoader and UrlRepoLoader functionality#38
sagar-18-07-2006 wants to merge 2 commits into
agsaru:mainfrom
sagar-18-07-2006:feature/testforurlloader

Conversation

@sagar-18-07-2006

@sagar-18-07-2006 sagar-18-07-2006 commented Jul 11, 2026

Copy link
Copy Markdown

Description

Closes #30

Summary

This PR adds a comprehensive test suite for repo2readme/loaders/loader.py, covering both LocalRepoLoader and UrlRepoLoader.

These loader classes are core components responsible for loading repository files, applying include/exclude filters, enriching document metadata, and managing temporary repositories. Previously, they had no dedicated unit tests.

What's Included

LocalRepoLoader

  • Added tests for constructor initialization.
  • Added tests for _should_include() filtering logic.
  • Added tests for loading files from a local repository.
  • Verified document metadata (file_path, file_name, file_type, and relative_path).
  • Added a test for FileNotFoundError when the repository path does not exist.
  • Added a test to ensure loader exceptions are handled gracefully without interrupting the loading process.

UrlRepoLoader

  • Added tests for constructor initialization.
  • Added parameterized tests for get_repo_name().
  • Added tests for _should_include().
  • Mocked GitLoader to test repository loading without performing real Git clones.
  • Verified metadata enrichment for loaded documents.
  • Added tests for temporary directory cleanup.

Benefits

  • Improves test coverage for one of the project's core modules.
  • Helps prevent regressions in repository loading, filtering, and metadata generation.
  • Keeps tests fast and deterministic by mocking external dependencies such as GitLoader and TextLoader.
  • Verifies expected behavior without requiring network access or real Git repositories.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **Tests**
  * Added comprehensive automated coverage for local and URL-based repository loading.
  * Verified repository path and branch parsing, file inclusion filters, metadata handling, and error behavior.
  * Added checks for temporary directory cleanup and graceful handling of loading failures.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b07f9c76-8563-4efa-ac72-d874ef8f0372

📥 Commits

Reviewing files that changed from the base of the PR and between db58cf6 and 29a3295.

📒 Files selected for processing (1)
  • tests/test_loader.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_loader.py

📝 Walkthrough

Walkthrough

Adds a pytest suite covering LocalRepoLoader and UrlRepoLoader, including initialization, filtering, metadata mapping, error handling, URL parsing, and temporary-directory cleanup.

Changes

Repository Loader Tests

Layer / File(s) Summary
Local loader validation
tests/test_loader.py
Tests LocalRepoLoader initialization, missing-path errors, include filtering, document metadata, and error handling during file loading.
URL loader validation
tests/test_loader.py
Tests UrlRepoLoader initialization, repository-name extraction, filtering, GitLoader metadata mapping, and cleanup behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Most requested tests are added, but the summary does not show coverage for max file-size, directory filtering, or exclude-pattern behavior from #30. Add tests for include/exclude patterns, max file-size skipping, and os.walk directory filtering for both loaders.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding unit tests for LocalRepoLoader and UrlRepoLoader.
Out of Scope Changes check ✅ Passed The change is confined to adding a new test file and matches the linked issue scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_loader.py (1)

42-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Mock assertions verify invocation but not arguments across three tests. The shared root cause is using assert_called_once() without assert_called_once_with(...), which confirms a mock was invoked but not that it received the correct parameters — regressions in argument passing would go undetected.

  • tests/test_loader.py#L42-L42: In test_should_include, verify github_file_filter was called with the correct relative_path (e.g., "a.py"), include_patterns, exclude_patterns, root_path, and max_file_size_kb.
  • tests/test_loader.py#L126-L126: In test_url_should_include, verify github_file_filter received relative_path="src/main.py", root_path="/tmp/repo", and the expected pattern/size parameters.
  • tests/test_loader.py#L154-L154: In test_url_load_metadata, verify GitLoader was constructed with the correct repo_path, clone_url, branch, and file_filter arguments.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_loader.py` at line 42, Replace the invocation-only mock assertions
with argument-specific assert_called_once_with checks in tests/test_loader.py at
lines 42-42, 126-126, and 154-154. In test_should_include, verify
github_file_filter receives relative_path "a.py", include_patterns,
exclude_patterns, root_path, and max_file_size_kb; in test_url_should_include,
verify relative_path "src/main.py", root_path "/tmp/repo", and the expected
pattern/size parameters; in test_url_load_metadata, verify GitLoader receives
the expected repo_path, clone_url, branch, and file_filter arguments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_loader.py`:
- Around line 129-154: Update test_url_load_metadata to call loader.cleanup()
after the assertions and mock_gitloader verification, ensuring the real
temporary directory created by loader.load() is removed while preserving the
existing metadata checks.

---

Nitpick comments:
In `@tests/test_loader.py`:
- Line 42: Replace the invocation-only mock assertions with argument-specific
assert_called_once_with checks in tests/test_loader.py at lines 42-42, 126-126,
and 154-154. In test_should_include, verify github_file_filter receives
relative_path "a.py", include_patterns, exclude_patterns, root_path, and
max_file_size_kb; in test_url_should_include, verify relative_path
"src/main.py", root_path "/tmp/repo", and the expected pattern/size parameters;
in test_url_load_metadata, verify GitLoader receives the expected repo_path,
clone_url, branch, and file_filter arguments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3d0c3ca7-a231-4f4c-a667-b911946ada13

📥 Commits

Reviewing files that changed from the base of the PR and between 7cd3542 and db58cf6.

📒 Files selected for processing (1)
  • tests/test_loader.py

Comment thread tests/test_loader.py Outdated
@agsaru

agsaru commented Jul 11, 2026

Copy link
Copy Markdown
Owner

@sagar-18-07-2006 the code changed so update yourself codebase and then create new tests cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add comprehensive tests for LocalRepoLoader and UrlRepoLoader

2 participants