Init
This commit is contained in:
BIN
tests/__pycache__/test_chunking.cpython-311-pytest-9.0.2.pyc
Normal file
BIN
tests/__pycache__/test_chunking.cpython-311-pytest-9.0.2.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_prompt.cpython-311-pytest-9.0.2.pyc
Normal file
BIN
tests/__pycache__/test_prompt.cpython-311-pytest-9.0.2.pyc
Normal file
Binary file not shown.
46
tests/test_chunking.py
Normal file
46
tests/test_chunking.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from ai_reviewer.diff import chunk_files, parse_diff
|
||||
|
||||
|
||||
def test_chunking_splits_on_hunks_when_large():
|
||||
diff_text = """
|
||||
diff --git a/app.py b/app.py
|
||||
index 0000000..1111111 100644
|
||||
--- a/app.py
|
||||
+++ b/app.py
|
||||
@@ -1,2 +1,2 @@
|
||||
-print('old')
|
||||
+print('new')
|
||||
@@ -10,2 +10,2 @@
|
||||
-x = 1
|
||||
+x = 2
|
||||
""".strip()
|
||||
|
||||
files = parse_diff(diff_text)
|
||||
chunks = chunk_files(files, max_lines=7)
|
||||
|
||||
assert len(chunks) == 2
|
||||
assert all(chunk.path == "app.py" for chunk in chunks)
|
||||
assert all(len(chunk.hunks) == 1 for chunk in chunks)
|
||||
|
||||
|
||||
def test_chunking_preserves_file_boundaries():
|
||||
diff_text = """
|
||||
diff --git a/a.txt b/a.txt
|
||||
--- a/a.txt
|
||||
+++ b/a.txt
|
||||
@@ -1 +1 @@
|
||||
-a
|
||||
+b
|
||||
diff --git a/b.txt b/b.txt
|
||||
--- a/b.txt
|
||||
+++ b/b.txt
|
||||
@@ -1 +1 @@
|
||||
-c
|
||||
+d
|
||||
""".strip()
|
||||
|
||||
files = parse_diff(diff_text)
|
||||
chunks = chunk_files(files, max_lines=50)
|
||||
|
||||
assert {chunk.path for chunk in chunks} == {"a.txt", "b.txt"}
|
||||
assert all(len(chunk.hunks) == 1 for chunk in chunks)
|
||||
10
tests/test_prompt.py
Normal file
10
tests/test_prompt.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from ai_reviewer.prompt import build_prompt
|
||||
|
||||
|
||||
def test_prompt_includes_diff_chunk_and_schema():
|
||||
chunk = "diff --git a/x.py b/x.py\n@@ -1 +1 @@\n-print(1)\n+print(2)\n"
|
||||
prompt = build_prompt(chunk)
|
||||
|
||||
assert "Output JSON schema" in prompt
|
||||
assert "Diff chunk:" in prompt
|
||||
assert chunk.strip() in prompt
|
||||
Reference in New Issue
Block a user