MCPcopy
hub / github.com/langroid/langroid / test_write_file_tool

Function test_write_file_tool

tests/main/test_file_tools.py:50–81  ·  view source on GitHub ↗
(test_settings: Settings, temp_dir, git_repo, agent)

Source from the content-addressed store, hash-verified

48
49
50def 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
84def test_write_file_tool_multiple_files(

Callers

nothing calls this directly

Calls 7

set_globalFunction · 0.90
llm_response_forgetMethod · 0.80
handle_messageMethod · 0.80
createMethod · 0.45
enable_messageMethod · 0.45
get_tool_messagesMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…