(test_settings: Settings, temp_dir, git_repo, agent)
| 48 | |
| 49 | |
| 50 | def test_write_file_tool(test_settings: Settings, temp_dir, git_repo, agent): |
| 51 | set_global(test_settings) |
| 52 | |
| 53 | custom_write_file_tool = WriteFileTool.create( |
| 54 | get_curr_dir=lambda: temp_dir, get_git_repo=lambda: git_repo |
| 55 | ) |
| 56 | agent.enable_message(custom_write_file_tool) |
| 57 | |
| 58 | content = "print('Hello, World!')" |
| 59 | file_path = "test_file.py" |
| 60 | |
| 61 | llm_msg = agent.llm_response_forget( |
| 62 | f"Write a Python file named '{file_path}' with the content: {content}" |
| 63 | ) |
| 64 | |
| 65 | assert isinstance(agent.get_tool_messages(llm_msg)[0], custom_write_file_tool) |
| 66 | |
| 67 | agent_result = agent.handle_message(llm_msg).content |
| 68 | assert f"Content written to {file_path}" in agent_result |
| 69 | assert "and committed" in agent_result |
| 70 | |
| 71 | # Check if the file was created |
| 72 | full_path = temp_dir / file_path |
| 73 | assert full_path.exists() |
| 74 | |
| 75 | # Check if the content was written correctly |
| 76 | with open(full_path, "r") as file: |
| 77 | assert file.read().strip() == content |
| 78 | |
| 79 | # Check if the file was committed to the git repo |
| 80 | assert not git_repo.is_dirty() |
| 81 | assert file_path in git_repo.git.ls_files().split() |
| 82 | |
| 83 | |
| 84 | def test_write_file_tool_multiple_files( |
nothing calls this directly
no test coverage detected
searching dependent graphs…