diff options
| author | Aman Sharma <210100011@iitb.ac.in> | 2024-12-17 14:00:33 +0530 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-12-19 11:33:18 +0100 |
| commit | f05edb2b43c347d4929efd52c8e2b4e08839f542 (patch) | |
| tree | 0765099eb2781e4bca8efd646b44683cea39b89a /tests | |
| parent | 3ee4c6a27ad520d4ecc3cded260d47cbccafb144 (diff) | |
Fixed #36016 -- Prevented traceback when quitting makemigrations with Ctrl-C.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_questioner.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/migrations/test_questioner.py b/tests/migrations/test_questioner.py index ec1013923b..5c737274e4 100644 --- a/tests/migrations/test_questioner.py +++ b/tests/migrations/test_questioner.py @@ -85,8 +85,9 @@ class QuestionerHelperMethodsTests(SimpleTestCase): @mock.patch("builtins.input", side_effect=[KeyboardInterrupt()]) def test_questioner_no_default_keyboard_interrupt(self, mock_input): - with self.assertRaises(KeyboardInterrupt): + with self.assertRaises(SystemExit): self.questioner._ask_default() + self.assertIn("Cancelled.\n", self.prompt.getvalue()) @mock.patch("builtins.input", side_effect=["", "n"]) def test_questioner_no_default_no_user_entry_boolean(self, mock_input): @@ -105,3 +106,18 @@ class QuestionerHelperMethodsTests(SimpleTestCase): expected_msg = f"{question}\n" f" 1) a\n" f" 2) b\n" f" 3) c\n" self.assertIn(expected_msg, self.prompt.getvalue()) self.assertEqual(value, 1) + + @mock.patch("builtins.input", side_effect=[KeyboardInterrupt()]) + def test_questioner_no_choice_keyboard_interrupt(self, mock_input): + question = "Make a choice:" + with self.assertRaises(SystemExit): + self.questioner._choice_input(question, choices="abc") + expected_msg = ( + f"{question}\n" + f" 1) a\n" + f" 2) b\n" + f" 3) c\n" + f"Select an option: \n" + f"Cancelled.\n" + ) + self.assertIn(expected_msg, self.prompt.getvalue()) |
