| 61 | |
| 62 | |
| 63 | class TestFileReadTool(unittest.TestCase): |
| 64 | def setUp(self): |
| 65 | self.tool = FileReadTool() |
| 66 | |
| 67 | def test_read_existing_file(self): |
| 68 | with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as f: |
| 69 | f.write("line1\nline2\nline3\n") |
| 70 | f.flush() |
| 71 | result = self.tool.execute({"path": f.name}) |
| 72 | self.assertFalse(result.is_error) |
| 73 | self.assertIn("line1", result.output) |
| 74 | self.assertIn("line2", result.output) |
| 75 | Path(f.name).unlink() |
| 76 | |
| 77 | def test_read_nonexistent(self): |
| 78 | result = self.tool.execute({"path": "/nonexistent/file.txt"}) |
| 79 | self.assertTrue(result.is_error) |
| 80 | |
| 81 | def test_read_with_offset_and_limit(self): |
| 82 | with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as f: |
| 83 | f.write("a\nb\nc\nd\ne\n") |
| 84 | f.flush() |
| 85 | result = self.tool.execute({"path": f.name, "offset": 2, "limit": 2}) |
| 86 | self.assertFalse(result.is_error) |
| 87 | self.assertIn("b", result.output) |
| 88 | self.assertIn("c", result.output) |
| 89 | self.assertNotIn("d", result.output) |
| 90 | Path(f.name).unlink() |
| 91 | |
| 92 | |
| 93 | class TestFileWriteTool(unittest.TestCase): |
nothing calls this directly
no outgoing calls
no test coverage detected