Esempio n. 1
0
 def test_prompt_setter(self):
     expected = 'new value'
     mock_callback = mock.MagicMock()
     mock_console = mock.Mock()
     shell = shellcommand.Shell(mock_callback, mock_console)
     shell.prompt = expected
     self.assertEqual(expected, shell.prompt)
Esempio n. 2
0
 def test_enter_succeeds(self):
     prompt = 'new prompt'
     exit_command = 'quit'
     mock_callback = mock.MagicMock()
     mock_console = mock.Mock()
     mock_console.input.side_effect = ['test command', exit_command]
     shell = shellcommand.Shell(mock_callback, mock_console)
     shell.exit_command = exit_command
     shell.prompt = prompt
     shell.enter()
     # ensure two prompts then exit
     input_calls = [mock.call(prompt), mock.call(prompt)]
     self.assertEqual(input_calls, mock_console.input.mock_calls)
Esempio n. 3
0
 def test_enter_handles_callback_exception(self):
     prompt = 'new prompt'
     exit_command = 'exit'
     mock_callback = mock.MagicMock()
     mock_callback.side_effect = Exception()
     mock_console = mock.Mock()
     mock_console.input = mock.MagicMock()
     mock_console.input.side_effect = ['test command', exit_command]
     shell = shellcommand.Shell(mock_callback, mock_console)
     shell.exit_command = exit_command
     shell.prompt = prompt
     shell.enter()
     # ensure still prompts after exception
     input_calls = [mock.call(prompt), mock.call(prompt)]
     self.assertEqual(input_calls, mock_console.input.mock_calls)
Esempio n. 4
0
 def test_constructor_handles_null_callback(self):
     mock_console = mock.Mock()
     with self.assertRaises(ValueError):
         shellcommand.Shell(None, mock_console)
Esempio n. 5
0
 def test_prompt_default(self):
     mock_callback = mock.MagicMock()
     mock_console = mock.Mock()
     shell = shellcommand.Shell(mock_callback, mock_console)
     self.assertEqual('> ', shell.prompt)
Esempio n. 6
0
 def test_exit_command_default(self):
     mock_callback = mock.MagicMock()
     mock_console = mock.Mock()
     shell = shellcommand.Shell(mock_callback, mock_console)
     self.assertEqual('exit', shell.exit_command)
Esempio n. 7
0
 def test_constructor_succeeds(self):
     mock_callback = mock.MagicMock()
     mock_console = mock.Mock()
     shellcommand.Shell(mock_callback, mock_console)