Skip to content

Commit 8137ce1

Browse files
test: add coverage for run_ingest_query and clone_repo async timeout (#129)
1 parent 5d5edee commit 8137ce1

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

tests/test_query_ingestion.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any
55
from unittest.mock import patch
66

7-
from gitingest.query_ingestion import _extract_files_content, _read_file_content, _scan_directory
7+
from gitingest.query_ingestion import _extract_files_content, _read_file_content, _scan_directory, run_ingest_query
88

99

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

155155

156+
def test_run_ingest_query(temp_directory: Path, sample_query: dict[str, Any]) -> None:
157+
"""
158+
Test the run_ingest_query function to ensure it processes the directory correctly.
159+
"""
160+
sample_query["local_path"] = temp_directory
161+
sample_query["subpath"] = "/"
162+
sample_query["type"] = None
163+
164+
summary, _, content = run_ingest_query(sample_query)
165+
166+
assert "Repository: test_user/test_repo" in summary
167+
assert "Files analyzed: 8" in summary
168+
assert "src/subfile1.txt" in content
169+
assert "src/subfile2.py" in content
170+
assert "src/subdir/file_subdir.txt" in content
171+
assert "src/subdir/file_subdir.py" in content
172+
assert "file1.txt" in content
173+
assert "file2.py" in content
174+
assert "dir1/file_dir1.txt" in content
175+
assert "dir2/file_dir2.txt" in content
176+
177+
156178
# multiple patterns
157179
# TODO: test with multiple include patterns: ['*.txt', '*.py']
158180
# TODO: test with multiple include patterns: ['/src/*', '*.txt']

tests/test_repository_clone.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
""" Tests for the repository_clone module. """
22

3+
import asyncio
34
from unittest.mock import AsyncMock, patch
45

56
import pytest
67

8+
from gitingest.exceptions import AsyncTimeoutError
79
from gitingest.repository_clone import CloneConfig, _check_repo_exists, clone_repo
810

911

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

235237
assert await _check_repo_exists(url)
238+
239+
240+
@pytest.mark.asyncio
241+
async def test_clone_repo_with_timeout() -> None:
242+
"""
243+
Test the `clone_repo` function when the cloning process exceeds the timeout limit.
244+
Verifies that an AsyncTimeoutError is raised.
245+
"""
246+
clone_config = CloneConfig(url="https://github.com/user/repo", local_path="/tmp/repo")
247+
248+
with patch("gitingest.repository_clone._check_repo_exists", return_value=True):
249+
with patch("gitingest.repository_clone._run_git_command", new_callable=AsyncMock) as mock_exec:
250+
mock_exec.side_effect = asyncio.TimeoutError
251+
with pytest.raises(AsyncTimeoutError, match="Operation timed out after"):
252+
await clone_repo(clone_config)

0 commit comments

Comments
 (0)