コード例 #1
0
 def test_prompt(self, message, prompt, default, parser, user_input,
                 expected_message, expected_prompt, expected_output):
     with mock.patch.object(utils, 'input',
                            return_value=user_input) as mock_input:
         with mock.patch.object(utils, 'write') as mock_write:
             actual_output = utils.prompt(message, prompt, default, parser)
             mock_write.assert_any_call(expected_message)
             self.assertEqual(mock_write.call_count, 4)
         mock_input.assert_called_once_with(expected_prompt)
     self.assertEqual(actual_output, expected_output)
コード例 #2
0
 def test_prompt__invalid_input(self):
     with mock.patch.object(utils, 'input',
                            side_effect=['INPUT', 'n']) as mock_input:
         with mock.patch.object(utils, 'write') as mock_write:
             self.assertFalse(
                 utils.prompt('MSG', None, None, utils.YesNoParser()))
             mock_write.assert_any_call(
                 "Invalid Response: 'INPUT'\nError: the value 'INPUT' is not a "
                 "'yes' or 'no'\nPlease try again.\n")
             self.assertEqual(mock_input.call_count, 2)
コード例 #3
0
 def test_prompt__invalid_parser(self, parser):
     with mock.patch.object(utils, 'input'):
         with self.assertRaises(NameError):
             utils.prompt('', None, None, parser)
コード例 #4
0
 def prompt(self):
     """Prompts the user for a new value."""
     self.value = utils.prompt(self.message,
                               default=self.value,
                               parser=self._parser)