Skip to content

Commit

Permalink
test: add coverage for run_ingest_query and clone_repo async timeout (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
filipchristiansen authored Jan 15, 2025
1 parent 5d5edee commit 8137ce1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/test_query_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any
from unittest.mock import patch

from gitingest.query_ingestion import _extract_files_content, _read_file_content, _scan_directory
from gitingest.query_ingestion import _extract_files_content, _read_file_content, _scan_directory, run_ingest_query


def test_scan_directory(temp_directory: Path, sample_query: dict[str, Any]) -> None:
Expand Down Expand Up @@ -153,6 +153,28 @@ def test_include_src_wildcard_prefix(temp_directory: Path, sample_query: dict[st
assert file_paths == expected_paths, "Missing or unexpected files in result"


def test_run_ingest_query(temp_directory: Path, sample_query: dict[str, Any]) -> None:
"""
Test the run_ingest_query function to ensure it processes the directory correctly.
"""
sample_query["local_path"] = temp_directory
sample_query["subpath"] = "/"
sample_query["type"] = None

summary, _, content = run_ingest_query(sample_query)

assert "Repository: test_user/test_repo" in summary
assert "Files analyzed: 8" in summary
assert "src/subfile1.txt" in content
assert "src/subfile2.py" in content
assert "src/subdir/file_subdir.txt" in content
assert "src/subdir/file_subdir.py" in content
assert "file1.txt" in content
assert "file2.py" in content
assert "dir1/file_dir1.txt" in content
assert "dir2/file_dir2.txt" in content


# multiple patterns
# TODO: test with multiple include patterns: ['*.txt', '*.py']
# TODO: test with multiple include patterns: ['/src/*', '*.txt']
Expand Down
17 changes: 17 additions & 0 deletions tests/test_repository_clone.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
""" Tests for the repository_clone module. """

import asyncio
from unittest.mock import AsyncMock, patch

import pytest

from gitingest.exceptions import AsyncTimeoutError
from gitingest.repository_clone import CloneConfig, _check_repo_exists, clone_repo


Expand Down Expand Up @@ -233,3 +235,18 @@ async def test_check_repo_exists_with_permanent_redirect() -> None:
mock_exec.return_value = mock_process

assert await _check_repo_exists(url)


@pytest.mark.asyncio
async def test_clone_repo_with_timeout() -> None:
"""
Test the `clone_repo` function when the cloning process exceeds the timeout limit.
Verifies that an AsyncTimeoutError is raised.
"""
clone_config = CloneConfig(url="https://github.com/user/repo", local_path="/tmp/repo")

with patch("gitingest.repository_clone._check_repo_exists", return_value=True):
with patch("gitingest.repository_clone._run_git_command", new_callable=AsyncMock) as mock_exec:
mock_exec.side_effect = asyncio.TimeoutError
with pytest.raises(AsyncTimeoutError, match="Operation timed out after"):
await clone_repo(clone_config)

0 comments on commit 8137ce1

Please sign in to comment.