def test_MantarrayProcessesManager__passes_file_directory_to_FileWriter(): manager = MantarrayProcessesManager(file_directory="blahdir") manager.create_processes() assert manager.get_file_writer_process().get_file_directory() == "blahdir" # clean up the ServerManager singleton clear_the_server_manager()
def test_MantarrayProcessesManager__passes_shared_values_dict_to_server(): expected_dict = {"beta_2_mode": False} manager = MantarrayProcessesManager( values_to_share_to_server=expected_dict) manager.create_processes() assert manager.get_server_manager().get_values_from_process_monitor( ) == expected_dict # clean up the ServerManager singleton clear_the_server_manager()
def fixture_generic_manager(): manager = MantarrayProcessesManager() yield manager if manager.are_subprocess_start_ups_complete( ) and not manager.are_processes_stopped(): manager.hard_stop_processes() # aspects of processes are often mocked just to assert they are called, so make sure to explicitly clean up the ServerManager module singleton clear_the_server_manager()
def test_get_server_port_number__returns_port_number_from_server_if_instantiated( generic_queue_container, ): to_main_queue = generic_queue_container.get_communication_queue_from_server_to_main( ) expected_port = 4321 ServerManager(to_main_queue, generic_queue_container, port=expected_port) assert get_server_port_number() == expected_port clear_the_server_manager()
def test_MantarrayProcessesManager__creates_mc_comm_instead_of_ok_comm_when_beta_2_flag_is_set_true( mocker, ): shared_values_dict = {"beta_2_mode": True} manager = MantarrayProcessesManager( values_to_share_to_server=shared_values_dict) manager.create_processes() mc_comm_process = manager.get_instrument_process() assert isinstance(mc_comm_process, McCommunicationProcess) is True # clean up the ServerManager singleton clear_the_server_manager()
def test_MantarrayProcessesManager__passes_logging_level_to_subprocesses(): expected_level = logging.WARNING manager = MantarrayProcessesManager(logging_level=expected_level) manager.create_processes() assert manager.get_file_writer_process().get_logging_level( ) == expected_level assert manager.get_instrument_process().get_logging_level( ) == expected_level assert manager.get_data_analyzer_process().get_logging_level( ) == expected_level assert manager.get_server_manager().get_logging_level() == expected_level # clean up the ServerManager singleton clear_the_server_manager()
def fixture_test_process_manager_creator(mocker): object_access_dict = {} def _foo(beta_2_mode=False, create_processes=True, use_testing_queues=False): if use_testing_queues: def get_testing_queue(): return TestingQueue() mocker.patch.object(queue_container, "Queue", autospec=True, side_effect=get_testing_queue) with tempfile.TemporaryDirectory() as tmp_dir: manager = MantarrayProcessesManager( file_directory=tmp_dir, values_to_share_to_server={ "beta_2_mode": beta_2_mode, "stored_customer_id": GENERIC_STORED_CUSTOMER_ID, "config_settings": dict(), }, ) if use_testing_queues: mocker.patch.object( manager, "start_processes", autospec=True, side_effect=NotImplementedError( "Cannot start processes when using a process_manager fixture setup with TestingQueues" ), ) if create_processes: manager.create_processes() object_access_dict[ "fw_process"] = manager.get_file_writer_process() return manager yield _foo fw_process = object_access_dict.get("fw_process", None) if fw_process is not None and not fw_process.is_alive(): # Eli (2/10/20): it is important in windows based systems to make sure to close the files before deleting them. be careful about this when running tests in a Linux development environment fw_process.close_all_files() # clean up the server singleton clear_the_server_manager()
def fixture_server_manager(generic_queue_container): # Tanner (8/10/21): it is the responsibility of tests using this fixture to drain the queues used to_main_queue = generic_queue_container.get_communication_queue_from_server_to_main( ) sm = ServerManager(to_main_queue, generic_queue_container) shared_values_dict = sm._values_from_process_monitor # pylint:disable=protected-access # Tanner (4/23/21): Many routes require these values to be in the shared values dictionary. They are normally set during app start up, so manually setting here shared_values_dict["system_status"] = SERVER_READY_STATE shared_values_dict["beta_2_mode"] = False shared_values_dict["config_settings"] = dict() yield sm, to_main_queue clear_the_server_manager()
def test_MantarrayProcessesManager__passes_beta_2_flag_to_subprocesses_other_than_instrument_comm( mocker, ): expected_beta_2_flag = True shared_values_dict = {"beta_2_mode": expected_beta_2_flag} manager = MantarrayProcessesManager( values_to_share_to_server=shared_values_dict) spied_fw_init = mocker.spy(FileWriterProcess, "__init__") spied_da_init = mocker.spy(DataAnalyzerProcess, "__init__") manager.create_processes() assert spied_fw_init.call_args.kwargs["beta_2_mode"] is expected_beta_2_flag assert spied_da_init.call_args.kwargs["beta_2_mode"] is expected_beta_2_flag # clean up the ServerManager singleton clear_the_server_manager()
def test_MantarrayProcessesManager__create_processes__passes_port_value_from_dictionary_to_server_manager( mocker, ): expected_port = 5432 manager = MantarrayProcessesManager(values_to_share_to_server={ "server_port_number": expected_port, "beta_2_mode": False, }) spied_create_server_manager = mocker.spy(ServerManager, "__init__") manager.create_processes() spied_create_server_manager.assert_called_once() assert spied_create_server_manager.call_args.kwargs[ "port"] == expected_port # clean up the ServerManager singleton clear_the_server_manager()
def test_get_server_port_number__returns_default_port_number_if_server_has_been_cleared( ): clear_the_server_manager() assert get_server_port_number() == DEFAULT_SERVER_PORT_NUMBER