File tree Expand file tree Collapse file tree 7 files changed +96
-1
lines changed Expand file tree Collapse file tree 7 files changed +96
-1
lines changed Original file line number Diff line number Diff line change
1
+ [run]
2
+ source = src
3
+ omit =
4
+ src/tests/*
5
+ src/*/__init__.py
6
+
7
+ [report]
8
+ exclude_lines =
9
+ pragma: no cover
10
+ def __repr__
11
+ raise NotImplementedError
12
+ if __name__ == .__main__.:
13
+ pass
14
+ raise ImportError
Original file line number Diff line number Diff line change @@ -22,6 +22,25 @@ You can also replace `hub` with `ingest` in any github url to access the corespo
22
22
- FastAPI - Backend framework
23
23
- [ apianalytics.dev] ( https://www.apianalytics.dev/ ) - Usage tracking
24
24
25
+ ## 📦 Running Tests
26
+
27
+ To run the tests, first install the test dependencies:
28
+ ``` bash
29
+ pip install -r requirements.txt
30
+ ```
31
+
32
+ Then run the tests with coverage:
33
+ ``` bash
34
+ cd src
35
+ pytest --cov
36
+ ```
37
+
38
+ To generate a coverage HTML report:
39
+ ``` bash
40
+ pytest --cov --cov-report=html
41
+ ```
42
+ The report will be available in ` htmlcov/index.html `
43
+
25
44
## 📦 Installation
26
45
27
46
1 . Clone the repository:
Original file line number Diff line number Diff line change
1
+ [pytest]
2
+ pythonpath = src
3
+ testpaths = src/tests
4
+ asyncio_mode = auto
5
+
6
+ # Coverage configuration
7
+ addopts = --cov =utils --cov =ingest --cov-report =term-missing --cov-report =html
Original file line number Diff line number Diff line change @@ -2,4 +2,7 @@ fastapi[standard]
2
2
uvicorn
3
3
fastapi-analytics
4
4
slowapi
5
- tokencost
5
+ tokencost
6
+ pytest
7
+ pytest-asyncio
8
+ pytest-cov
Original file line number Diff line number Diff line change
1
+ import os
2
+ import sys
3
+
4
+ # Get the absolute path of the src directory
5
+ src_path = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
6
+
7
+ # Add the path to PYTHONPATH
8
+ sys .path .insert (0 , src_path )
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ from utils .clone import clone_repo
3
+ from unittest .mock import patch , AsyncMock
4
+
5
+ @pytest .mark .asyncio
6
+ async def test_clone_repo_with_commit ():
7
+ query = {
8
+ 'commit' : 'a' * 40 , # Simulating a valid commit hash
9
+ 'branch' : 'main' ,
10
+ 'url' : 'https://github.com/user/repo' ,
11
+ 'local_path' : '/tmp/repo'
12
+ }
13
+ with patch ('asyncio.create_subprocess_exec' , new_callable = AsyncMock ) as mock_exec :
14
+ await clone_repo (query )
15
+ assert mock_exec .call_count == 2 # Ensure both clone and checkout are called
16
+
17
+ @pytest .mark .asyncio
18
+ async def test_clone_repo_without_commit ():
19
+ query = {
20
+ 'commit' : None ,
21
+ 'branch' : 'main' ,
22
+ 'url' : 'https://github.com/user/repo' ,
23
+ 'local_path' : '/tmp/repo'
24
+ }
25
+ with patch ('asyncio.create_subprocess_exec' , new_callable = AsyncMock ) as mock_exec :
26
+ await clone_repo (query )
27
+ assert mock_exec .call_count == 1 # Ensure only clone is called
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ from utils .parse_url import parse_url
3
+
4
+ def test_parse_url_valid ():
5
+ url = "https://github.com/user/repo"
6
+ max_file_size = 100
7
+ result = parse_url (url , max_file_size )
8
+ assert result ["user_name" ] == "user"
9
+ assert result ["repo_name" ] == "repo"
10
+ assert result ["url" ] == "https://github.com/user/repo"
11
+ assert result ["max_file_size" ] == 100 * 1024
12
+
13
+ def test_parse_url_invalid ():
14
+ url = "https://invalid.com/user/repo"
15
+ max_file_size = 100
16
+ with pytest .raises (ValueError , match = "Invalid GitHub URL" ):
17
+ parse_url (url , max_file_size )
You can’t perform that action at this time.
0 commit comments