| 83 | |
| 84 | @patch('tools.search_engine.DDGS') |
| 85 | def test_search_error(self, mock_ddgs): |
| 86 | # Mock search error |
| 87 | mock_ddgs_instance = MagicMock() |
| 88 | mock_ddgs_instance.__enter__.return_value.text.side_effect = Exception("Test error") |
| 89 | mock_ddgs.return_value = mock_ddgs_instance |
| 90 | |
| 91 | # Run search and check for error |
| 92 | with self.assertRaises(SystemExit) as cm: |
| 93 | search("test query") |
| 94 | |
| 95 | self.assertEqual(cm.exception.code, 1) |
| 96 | self.assertIn("ERROR: Search failed: Test error", self.stderr.getvalue()) |
| 97 | |
| 98 | def test_result_field_fallbacks(self): |
| 99 | # Test that the fields work correctly with N/A fallback |