fix grep
This commit is contained in:
@@ -274,10 +274,10 @@ class CodingTools:
|
||||
"""
|
||||
resolved: str = self._resolve_path(path)
|
||||
try:
|
||||
command: str = f"grep -ri '{pattern}' {resolved}"
|
||||
command: list[str] = ["grep", "-ri", pattern, resolved]
|
||||
process: subprocess.Popen[str] = subprocess.Popen(
|
||||
command,
|
||||
shell=True,
|
||||
shell=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
|
||||
@@ -126,8 +126,17 @@ def test_grep_search_success(mock_popen: MagicMock) -> None:
|
||||
mock_process.returncode = 0
|
||||
mock_popen.return_value = mock_process
|
||||
|
||||
res: str = CodingTools().grep_search("pattern", "/path")
|
||||
tools = CodingTools()
|
||||
res: str = tools.grep_search("pattern", "/path")
|
||||
assert res == "match_line"
|
||||
mock_popen.assert_called_once_with(
|
||||
["grep", "-ri", "pattern", tools._resolve_path("/path")],
|
||||
shell=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
cwd=tools.repo_path,
|
||||
)
|
||||
|
||||
|
||||
@patch("subprocess.Popen")
|
||||
@@ -137,8 +146,17 @@ def test_grep_search_no_matches(mock_popen: MagicMock) -> None:
|
||||
mock_process.returncode = 1
|
||||
mock_popen.return_value = mock_process
|
||||
|
||||
res: str = CodingTools().grep_search("pattern", "/path")
|
||||
tools = CodingTools()
|
||||
res: str = tools.grep_search("pattern", "/path")
|
||||
assert "No matches found" in res
|
||||
mock_popen.assert_called_once_with(
|
||||
["grep", "-ri", "pattern", tools._resolve_path("/path")],
|
||||
shell=False,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
cwd=tools.repo_path,
|
||||
)
|
||||
|
||||
|
||||
def test_grep_search_error() -> None:
|
||||
|
||||
Reference in New Issue
Block a user