diff --git a/tests/basic/test_io.py b/tests/basic/test_io.py index 05770ef01..f68a46127 100644 --- a/tests/basic/test_io.py +++ b/tests/basic/test_io.py @@ -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 = []