mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
fix: ensure the entire file will be read when the start_line is None (#325)
This commit is contained in:
@@ -59,11 +59,13 @@ class FileReadTool(BaseTool):
|
|||||||
|
|
||||||
def _run(
|
def _run(
|
||||||
self,
|
self,
|
||||||
**kwargs: Any,
|
file_path: Optional[str] = None,
|
||||||
|
start_line: Optional[int] = 1,
|
||||||
|
line_count: Optional[int] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
file_path = kwargs.get("file_path", self.file_path)
|
file_path = file_path or self.file_path
|
||||||
start_line = kwargs.get("start_line", 1)
|
start_line = start_line or 1
|
||||||
line_count = kwargs.get("line_count", None)
|
line_count = line_count or None
|
||||||
|
|
||||||
if file_path is None:
|
if file_path is None:
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -139,6 +139,11 @@ def test_file_read_tool_zero_or_negative_start_line():
|
|||||||
with patch("builtins.open", mock_open(read_data=file_content)):
|
with patch("builtins.open", mock_open(read_data=file_content)):
|
||||||
tool = FileReadTool()
|
tool = FileReadTool()
|
||||||
|
|
||||||
|
# Test with start_line = None
|
||||||
|
result = tool._run(file_path=test_file, start_line=None)
|
||||||
|
expected = "".join(lines) # Should read the entire file
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
# Test with start_line = 0
|
# Test with start_line = 0
|
||||||
result = tool._run(file_path=test_file, start_line=0)
|
result = tool._run(file_path=test_file, start_line=0)
|
||||||
expected = "".join(lines) # Should read the entire file
|
expected = "".join(lines) # Should read the entire file
|
||||||
|
|||||||
Reference in New Issue
Block a user