Skip to content

Commit 1836809

Browse files
Enhancements: CLI Test Cases (#144)
1 parent 71b1167 commit 1836809

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

src/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
MAX_TOTAL_SIZE_BYTES = 500 * 1024 * 1024 # 500 MB
99

1010
MAX_DISPLAY_SIZE: int = 300_000
11-
TMP_BASE_PATH = Path("/tmp/gitingest")
1211
DELETE_REPO_AFTER: int = 60 * 60 # In seconds
1312

13+
OUTPUT_FILE_PATH = "digest.txt"
14+
TMP_BASE_PATH = Path("/tmp/gitingest")
15+
1416
EXAMPLE_REPOS: list[dict[str, str]] = [
1517
{"name": "Gitingest", "url": "https://github.com/cyclotruc/gitingest"},
1618
{"name": "FastAPI", "url": "https://github.com/tiangolo/fastapi"},

src/gitingest/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import click
88

9-
from config import MAX_FILE_SIZE
9+
from config import MAX_FILE_SIZE, OUTPUT_FILE_PATH
1010
from gitingest.repository_ingest import ingest
1111

1212

@@ -84,7 +84,7 @@ async def _async_main(
8484
include_patterns = set(include_pattern)
8585

8686
if not output:
87-
output = "digest.txt"
87+
output = OUTPUT_FILE_PATH
8888
summary, _, _ = await ingest(source, max_size, include_patterns, exclude_patterns, output=output)
8989

9090
click.echo(f"Analysis complete! Output written to: {output}")

tests/test_cli.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
""" Tests for the gitingest cli """
2+
3+
import os
4+
5+
from click.testing import CliRunner
6+
7+
from config import MAX_FILE_SIZE, OUTPUT_FILE_PATH
8+
from gitingest.cli import main
9+
10+
11+
def test_cli_with_default_options():
12+
runner = CliRunner()
13+
result = runner.invoke(main, ["./"])
14+
output_lines = result.output.strip().split("\n")
15+
assert f"Analysis complete! Output written to: {OUTPUT_FILE_PATH}" in output_lines
16+
assert os.path.exists(OUTPUT_FILE_PATH), f"Output file was not created at {OUTPUT_FILE_PATH}"
17+
18+
os.remove(OUTPUT_FILE_PATH)
19+
20+
21+
def test_cli_with_options():
22+
runner = CliRunner()
23+
result = runner.invoke(
24+
main,
25+
[
26+
"./",
27+
"--output",
28+
OUTPUT_FILE_PATH,
29+
"--max-size",
30+
MAX_FILE_SIZE,
31+
"--exclude-pattern",
32+
"tests/",
33+
"--include-pattern",
34+
"src/",
35+
],
36+
)
37+
output_lines = result.output.strip().split("\n")
38+
assert f"Analysis complete! Output written to: {OUTPUT_FILE_PATH}" in output_lines
39+
assert os.path.exists(OUTPUT_FILE_PATH), f"Output file was not created at {OUTPUT_FILE_PATH}"
40+
41+
os.remove(OUTPUT_FILE_PATH)

0 commit comments

Comments
 (0)