def test_initialise_enabled(self, mock_cfg, mock_thread): mock_cfg.overall_config.diagnostics_enabled.return_value = True mock_cfg.overall_config.diagnostics_port.return_value = 5000 thread = Mock() mock_thread.return_value = thread Diagnostics.initialise() mock_thread.assert_called_with( target=Diagnostics._make_socket_connection, args=[5000]) thread.start.assert_called_with()
def test_initialise_not_enabled(self, mock_cfg, mock_thread): mock_cfg.overall_config.diagnostics_enabled.return_value = False Diagnostics.initialise() mock_cfg.overall_config.diagnostics_enabled.assert_called_with() mock_cfg.overall_config.diagnostics_port.assert_not_called() mock_thread.assert_not_called()
def main(argv): '''Rover operation starts here! Wait for a connection from a remote computer, interpret commands received and take appropriate action. ''' if len(argv) < 2 and len(argv) > 4: dg.print(usage_str) sys.exit(1) if argv[1] == '--as-unit': # not the main unit process_as_unit(argv) return # The rest of main() should only run on the main unit try: port = int(argv[1]) # port to receive commands on except ValueError: dg.print("Port number should be an integer") sys.exit(1) # exit with error code try: if len(argv) == 3: # settings file specified cfg.Configuration.settings_file(argv[2]) else: # use the default settings file (settings.xml) cfg.Configuration.settings_file() except cfg.ConfigurationError as e: # error related to settings file dg.print(str(e) + "\nExiting...") sys.exit(1) # exit with error code try: OpMode.opmodes_initialise() # check for available operational modes except OpModeError as e: dg.print(str(e) + "\nExiting...") sys.exit(1) # exit with error code if OpMode.get_all(): # list of registered modes is not empty dg.print("Found operational modes: ") for name in OpMode.get_all_names(): # print registered names of all modes dg.print(' ' + name) try: mgr.global_resources.initialise() # get all resources ready # (motors, camera, etc) except mgr.ResourceError as e: dg.print(str(e) + "\nExiting...") sys.exit(1) # exit with error code dg.initialise() # start diagnostics unit.activate_main_unit_services( ) # service connections from attached units # start operation while (True): dg.print("Waiting for connection...") try: main_sock = wait_for_remote(port) host, _ = main_sock.get_ip_address() cfg.overall_config.set_ip(host) except TcpSocketError as e: # connection error dg.print(str(e)) cleanup() continue # wait for connection again shutdown = run(main_sock) if shutdown: break cleanup() unit.deactivate_main_unit_services() dg.close() sys.exit(0) # shutdown