mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-17 15:35:21 +02:00
feat: merge mgx_ops
This commit is contained in:
commit
9afb00d873
10 changed files with 199 additions and 29 deletions
|
|
@ -44,6 +44,15 @@ def temp_py_file(tmp_path):
|
|||
temp_file_path.unlink()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def empty_file(tmp_path):
|
||||
assert tmp_path is not None
|
||||
temp_file_path = tmp_path / "test_script_empty_file_for_editor.py"
|
||||
temp_file_path.write_text("")
|
||||
yield temp_file_path
|
||||
temp_file_path.unlink()
|
||||
|
||||
|
||||
EXPECTED_CONTENT_AFTER_REPLACE = """
|
||||
# this is line one
|
||||
def test_function_for_fm():
|
||||
|
|
@ -529,6 +538,15 @@ def test_edit_file_by_replace(temp_py_file):
|
|||
assert new_content.strip() == EXPECTED_CONTENT_AFTER_REPLACE_TEXT.strip()
|
||||
|
||||
|
||||
def test_edit_file_by_replace_to_palce_empty(empty_file):
|
||||
editor = Editor()
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
editor.edit_file_by_replace(
|
||||
file_name=str(empty_file), to_replace="", new_content=EXPECTED_CONTENT_AFTER_REPLACE_TEXT.strip()
|
||||
)
|
||||
assert "is empty. Use the append method to add content." in str(exc_info.value)
|
||||
|
||||
|
||||
def test_append_file(temp_file_path):
|
||||
editor = Editor()
|
||||
# 写入初始内容
|
||||
|
|
@ -585,6 +603,27 @@ def test_search_dir(tmp_path):
|
|||
assert "Another file with different content." not in result
|
||||
|
||||
|
||||
def test_search_dir_in_default_dir(tmp_path):
|
||||
editor = Editor()
|
||||
dir_path = editor.working_dir / "test_dir"
|
||||
dir_path.mkdir(exist_ok=True)
|
||||
|
||||
# Create some files with specific content
|
||||
(dir_path / "file1.txt").write_text("This is a test file with some content.")
|
||||
(dir_path / "file2.txt").write_text("Another file with different content.")
|
||||
sub_dir = dir_path / "sub_dir"
|
||||
sub_dir.mkdir(exist_ok=True)
|
||||
(sub_dir / "file3.txt").write_text("This file is inside a sub directory with some content.")
|
||||
|
||||
search_term = "some content"
|
||||
|
||||
result = editor.search_dir(search_term)
|
||||
|
||||
assert "file1.txt" in result
|
||||
assert "file3.txt" in result
|
||||
assert "Another file with different content." not in result
|
||||
|
||||
|
||||
def test_search_file(temp_file_path):
|
||||
editor = Editor()
|
||||
file_path = temp_file_path
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue