| 167 | |
| 168 | |
| 169 | class TestGrepTool(unittest.TestCase): |
| 170 | def setUp(self): |
| 171 | self.tool = GrepTool() |
| 172 | |
| 173 | def test_search_in_file(self): |
| 174 | with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f: |
| 175 | f.write("def hello():\n return 'world'\n") |
| 176 | f.flush() |
| 177 | result = self.tool.execute({"pattern": "hello", "path": f.name}) |
| 178 | self.assertFalse(result.is_error) |
| 179 | self.assertIn("hello", result.output) |
| 180 | Path(f.name).unlink() |
| 181 | |
| 182 | def test_no_matches(self): |
| 183 | with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f: |
| 184 | f.write("nothing here\n") |
| 185 | f.flush() |
| 186 | result = self.tool.execute({"pattern": "zzzzz", "path": f.name}) |
| 187 | self.assertIn("No matches", result.output) |
| 188 | Path(f.name).unlink() |
| 189 | |
| 190 | |
| 191 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected