forked from cyclotruc/gitingest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests and coverage configuration (cyclotruc#28)
Co-authored-by: Mohamed Azerkane <mohamed.azerkane@cure51.com>
- Loading branch information
1 parent
9d7019e
commit 823f01b
Showing
7 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[run] | ||
source = src | ||
omit = | ||
src/tests/* | ||
src/*/__init__.py | ||
|
||
[report] | ||
exclude_lines = | ||
pragma: no cover | ||
def __repr__ | ||
raise NotImplementedError | ||
if __name__ == .__main__.: | ||
pass | ||
raise ImportError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[pytest] | ||
pythonpath = src | ||
testpaths = src/tests | ||
asyncio_mode = auto | ||
|
||
# Coverage configuration | ||
addopts = --cov=utils --cov=ingest --cov-report=term-missing --cov-report=html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,7 @@ fastapi[standard] | |
uvicorn | ||
fastapi-analytics | ||
slowapi | ||
tokencost | ||
tokencost | ||
pytest | ||
pytest-asyncio | ||
pytest-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import os | ||
import sys | ||
|
||
# Get the absolute path of the src directory | ||
src_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
# Add the path to PYTHONPATH | ||
sys.path.insert(0, src_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
from utils.clone import clone_repo | ||
from unittest.mock import patch, AsyncMock | ||
|
||
@pytest.mark.asyncio | ||
async def test_clone_repo_with_commit(): | ||
query = { | ||
'commit': 'a' * 40, # Simulating a valid commit hash | ||
'branch': 'main', | ||
'url': 'https://github.com/user/repo', | ||
'local_path': '/tmp/repo' | ||
} | ||
with patch('asyncio.create_subprocess_exec', new_callable=AsyncMock) as mock_exec: | ||
await clone_repo(query) | ||
assert mock_exec.call_count == 2 # Ensure both clone and checkout are called | ||
|
||
@pytest.mark.asyncio | ||
async def test_clone_repo_without_commit(): | ||
query = { | ||
'commit': None, | ||
'branch': 'main', | ||
'url': 'https://github.com/user/repo', | ||
'local_path': '/tmp/repo' | ||
} | ||
with patch('asyncio.create_subprocess_exec', new_callable=AsyncMock) as mock_exec: | ||
await clone_repo(query) | ||
assert mock_exec.call_count == 1 # Ensure only clone is called |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
from utils.parse_url import parse_url | ||
|
||
def test_parse_url_valid(): | ||
url = "https://github.com/user/repo" | ||
max_file_size = 100 | ||
result = parse_url(url, max_file_size) | ||
assert result["user_name"] == "user" | ||
assert result["repo_name"] == "repo" | ||
assert result["url"] == "https://github.com/user/repo" | ||
assert result["max_file_size"] == 100 * 1024 | ||
|
||
def test_parse_url_invalid(): | ||
url = "https://invalid.com/user/repo" | ||
max_file_size = 100 | ||
with pytest.raises(ValueError, match="Invalid GitHub URL"): | ||
parse_url(url, max_file_size) |