mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-21 07:54:21 +01:00
Fix split_file when overlap = 0, add test (#3599)
Co-authored-by: Nicholas Tindle <nick@ntindle.com>
This commit is contained in:
@@ -131,7 +131,7 @@ def split_file(
|
|||||||
while start < content_length:
|
while start < content_length:
|
||||||
end = start + max_length
|
end = start + max_length
|
||||||
if end + overlap < content_length:
|
if end + overlap < content_length:
|
||||||
chunk = content[start : end + overlap - 1]
|
chunk = content[start : end + max(overlap - 1, 0)]
|
||||||
else:
|
else:
|
||||||
chunk = content[start:content_length]
|
chunk = content[start:content_length]
|
||||||
|
|
||||||
|
|||||||
@@ -151,12 +151,41 @@ def test_log_operation_with_checksum(config: Config):
|
|||||||
assert f"log_test: path/to/test #ABCDEF\n" in content
|
assert f"log_test: path/to/test #ABCDEF\n" in content
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"max_length, overlap, content, expected",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
4,
|
||||||
|
1,
|
||||||
|
"abcdefghij",
|
||||||
|
["abcd", "defg", "ghij"],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
4,
|
||||||
|
0,
|
||||||
|
"abcdefghijkl",
|
||||||
|
["abcd", "efgh", "ijkl"],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
4,
|
||||||
|
0,
|
||||||
|
"abcdefghijklm",
|
||||||
|
["abcd", "efgh", "ijkl", "m"],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
4,
|
||||||
|
0,
|
||||||
|
"abcdefghijk",
|
||||||
|
["abcd", "efgh", "ijk"],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
# Test splitting a file into chunks
|
# Test splitting a file into chunks
|
||||||
def test_split_file():
|
def test_split_file(max_length, overlap, content, expected):
|
||||||
content = "abcdefghij"
|
assert (
|
||||||
chunks = list(file_ops.split_file(content, max_length=4, overlap=1))
|
list(file_ops.split_file(content, max_length=max_length, overlap=overlap))
|
||||||
expected = ["abcd", "defg", "ghij"]
|
== expected
|
||||||
assert chunks == expected
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_read_file(test_file_with_content_path: Path, file_content):
|
def test_read_file(test_file_with_content_path: Path, file_content):
|
||||||
|
|||||||
Reference in New Issue
Block a user