| 8 | |
| 9 | |
| 10 | class TestBashTool(unittest.IsolatedAsyncioTestCase): |
| 11 | def setUp(self): |
| 12 | self.tool = BashTool() |
| 13 | |
| 14 | async def asyncTearDown(self): |
| 15 | # Cleanup any active session |
| 16 | if self.tool._session: |
| 17 | await self.tool._session.stop() |
| 18 | |
| 19 | async def test_tool_initialization(self): |
| 20 | self.assertEqual(self.tool.get_name(), "bash") |
| 21 | self.assertIn("Run commands in a bash shell", self.tool.get_description()) |
| 22 | |
| 23 | params = self.tool.get_parameters() |
| 24 | param_names = [p.name for p in params] |
| 25 | self.assertIn("command", param_names) |
| 26 | self.assertIn("restart", param_names) |
| 27 | |
| 28 | async def test_command_error_handling(self): |
| 29 | result = await self.tool.execute(ToolCallArguments({"command": "invalid_command_123"})) |
| 30 | |
| 31 | # Fix assertion: Check if error message contains 'not found' or 'not recognized' (Windows system) |
| 32 | self.assertTrue(any(s in result.error.lower() for s in ["not found", "not recognized"])) |
| 33 | self.assertNotEqual(result.error_code, 0) |
| 34 | |
| 35 | async def test_session_restart(self): |
| 36 | # Ensure session is initialized |
| 37 | await self.tool.execute(ToolCallArguments({"command": "echo first session"})) |
| 38 | |
| 39 | # Fix: Check if session object exists |
| 40 | self.assertIsNotNone(self.tool._session) |
| 41 | |
| 42 | # Restart and test new session |
| 43 | restart_result = await self.tool.execute(ToolCallArguments({"restart": True})) |
| 44 | self.assertIn("restarted", restart_result.output.lower()) |
| 45 | |
| 46 | # Fix: Ensure new session is created |
| 47 | self.assertIsNotNone(self.tool._session) |
| 48 | |
| 49 | # Verify new session works |
| 50 | result = await self.tool.execute(ToolCallArguments({"command": "echo new session"})) |
| 51 | self.assertIn("new session", result.output) |
| 52 | |
| 53 | async def test_successful_command_execution(self): |
| 54 | result = await self.tool.execute(ToolCallArguments({"command": "echo hello world"})) |
| 55 | |
| 56 | # Fix: Check if return code is 0 |
| 57 | self.assertEqual(result.error_code, 0) |
| 58 | self.assertIn("hello world", result.output) |
| 59 | self.assertEqual(result.error, "") |
| 60 | |
| 61 | async def test_missing_command_handling(self): |
| 62 | result = await self.tool.execute(ToolCallArguments({})) |
| 63 | self.assertIn("no command provided", result.error.lower()) |
| 64 | self.assertEqual(result.error_code, -1) |
| 65 | |
| 66 | |
| 67 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected