MCPcopy Create free account
hub / github.com/bcefghj/miniClaudeCode / TestFileEditTool

Class TestFileEditTool

tests/test_tools.py:112–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110
111
112class TestFileEditTool(unittest.TestCase):
113 def setUp(self):
114 self.tool = FileEditTool()
115
116 def test_replace_unique_string(self):
117 with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as f:
118 f.write("hello world\nfoo bar\n")
119 f.flush()
120 result = self.tool.execute({
121 "path": f.name,
122 "old_string": "foo bar",
123 "new_string": "baz qux",
124 })
125 self.assertFalse(result.is_error)
126 self.assertEqual(Path(f.name).read_text(), "hello world\nbaz qux\n")
127 Path(f.name).unlink()
128
129 def test_reject_non_unique(self):
130 with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as f:
131 f.write("aaa\naaa\n")
132 f.flush()
133 result = self.tool.execute({
134 "path": f.name,
135 "old_string": "aaa",
136 "new_string": "bbb",
137 })
138 self.assertTrue(result.is_error)
139 self.assertIn("2 times", result.output)
140 Path(f.name).unlink()
141
142 def test_reject_not_found(self):
143 with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as f:
144 f.write("hello\n")
145 f.flush()
146 result = self.tool.execute({
147 "path": f.name,
148 "old_string": "xyz",
149 "new_string": "abc",
150 })
151 self.assertTrue(result.is_error)
152 Path(f.name).unlink()
153
154
155class TestGlobTool(unittest.TestCase):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected