test: add unit tests for allow_never option in confirm_ask method

This commit is contained in:
Paul Gauthier (aider) 2024-09-28 15:16:56 -07:00
parent b78d19c7a5
commit ec10ead0c3

View file

@ -159,6 +159,46 @@ class TestInputOutput(unittest.TestCase):
mock_input.assert_called_once()
mock_input.reset_mock()
@patch("builtins.input", side_effect=["d"])
def test_confirm_ask_allow_never(self, mock_input):
io = InputOutput(pretty=False)
# First call: user selects "Don't ask again"
result = io.confirm_ask("Are you sure?", allow_never=True)
self.assertFalse(result)
mock_input.assert_called_once()
self.assertIn(("Are you sure?", None), io.never_prompts)
# Reset the mock to check for further calls
mock_input.reset_mock()
# Second call: should not prompt, immediately return False
result = io.confirm_ask("Are you sure?", allow_never=True)
self.assertFalse(result)
mock_input.assert_not_called()
# Test with subject parameter
mock_input.reset_mock()
mock_input.side_effect = ["d"]
result = io.confirm_ask("Confirm action?", subject="Subject Text", allow_never=True)
self.assertFalse(result)
mock_input.assert_called_once()
self.assertIn(("Confirm action?", "Subject Text"), io.never_prompts)
# Subsequent call with the same question and subject
mock_input.reset_mock()
result = io.confirm_ask("Confirm action?", subject="Subject Text", allow_never=True)
self.assertFalse(result)
mock_input.assert_not_called()
# Test that allow_never=False does not add to never_prompts
mock_input.reset_mock()
mock_input.side_effect = ["d"]
result = io.confirm_ask("Do you want to proceed?", allow_never=False)
self.assertFalse(result)
mock_input.assert_called_once()
self.assertNotIn(("Do you want to proceed?", None), io.never_prompts)
def test_get_command_completions(self):
root = ""
rel_fnames = []