def test_wait_connection_error(self, mock_sock): '''TcpSocketError raised while waiting for connection from remote. > Program must terminate.''' mock_sock.return_value.wait_for_connection.side_effect\ = start_rover.TcpSocketError with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '2409', 'RaspiCode/debug.xml'])
def test_resource_manager_initialise_error(self, mock_mgr): '''ResourceError raised during global_resources.initialise(). > global_resources.initialise must be called and program must terminate.''' mock_mgr.initialise.side_effect = start_rover.mgr.ResourceError with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '5560', 'RaspiCode/debug.xml']) mock_mgr.initialise.assert_called_with()
def test_opmode_initialise_error(self, mock_opmode): '''OpModeError raised during OpMode.opmodes_initialise(). > OpMode.opmodes_initialise must be called and program must terminate.''' mock_opmode.opmodes_initialise.side_effect = start_rover.OpModeError with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '5560', 'RaspiCode/debug.xml']) mock_opmode.opmodes_initialise.assert_called_with()
def test_bad_settings(self, mock_cfg): '''ConfigurationError raised by configuration manager when initialising using specified settings file. > Configuration.settings_file() must be called, and program must terminate.''' mock_cfg.settings_file.side_effect = start_rover.cfg.ConfigurationError with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '5560', 'debug.xml']) mock_cfg.settings_file.assert_called_with('debug.xml')
def test_read_error(self, mock_sock): '''TcpSocketError raised while receiving command from remote. > Program must terminate after calling launcher.release_all() to stop any active modes.''' start_rover.launcher.release_all = method_call_logger(\ start_rover.launcher.release_all) mock_sock.return_value.read.side_effect = start_rover.TcpSocketError with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '2409', 'RaspiCode/debug.xml']) assert (start_rover.launcher.release_all.was_called)
def test_read_connection_drop(self, mock_sock): '''Connection terminated (EOF) by remote. > Program must terminate after calling launcher.release_all() to stop any active modes.''' start_rover.launcher.release_all = method_call_logger(\ start_rover.launcher.release_all) mock_sock.return_value.read.return_value = None with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '2409', 'RaspiCode/debug.xml']) assert (start_rover.launcher.release_all.was_called)
def test_command_error(self, mock_sock, mock_parser): '''CommandError raised by parse_entry. Test makes use of TcpSocketError on TcpSocket.reply so that the test can terminate. > Must send reply to remote containing the error string.''' mock_sock.return_value.read.return_value = "SOME BAD COMMAND" mock_sock.return_value.reply.side_effect = start_rover.TcpSocketError err_string = "bad command" mock_parser.side_effect = start_rover.CommandError(err_string) with self.assertRaises(start_rover.TcpSocketError): start_rover.main(['start_rover.py', '3500', 'RaspiCode/debug.xml']) mock_sock.return_value.reply.assert_called_with(err_string)
def test_reply_error(self, mock_parser, mock_sock): '''TcpSocketError raised while replying to remote after a valid command was received. > Program must terminate after calling launcher.release_all() to stop any active modes. parse_entry should have been called with the right command. TcpSocket.reply() should have been called with 'ACK'.''' start_rover.launcher.release_all = method_call_logger(\ start_rover.launcher.release_all) mock_sock.return_value.read.return_value = 'STOP_JOYSTICK' mock_sock.return_value.reply.side_effect = start_rover.TcpSocketError with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '2409', 'RaspiCode/debug.xml']) mock_parser.assert_called_with('STOP_JOYSTICK') mock_sock.return_value.reply.assert_called_with('ACK') assert (start_rover.launcher.release_all.was_called)
def test_wrong_args(self): '''Invalid arguments to start the program. > Program must terminate.''' with self.assertRaises(SystemExit): # too many arguments start_rover.main( ['start_rover.py', '3500', 'blablba', 'RaspiCode/debug.xml']) with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '-2']) # negative with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '-2', 'RaspiCode/debug.xml']) # negative with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '2.5']) # float with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '2.5', 'RaspiCode/debug.xml']) # float with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '100']) # too small with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', '50000000']) # too large with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', 'one']) # port should be int with self.assertRaises(SystemExit): start_rover.main(['start_rover.py', 'RaspiCode/debug.xml']) # no port