def test_log_file_has_sub_process_entries(self): """ This test documents the alternative: slurp the log results back in from the log file and then do the text matches. """ assert applog.delete_log_file_if_exists() == True main_logger = applog.MainLogger() log_queue = main_logger.log_queue sub_proc = multiprocessing.Process(target=self.worker_process, args=(log_queue, )) sub_proc.start() time.sleep(1.0) # make sure the process has enough time to emit main_logger.close() time.sleep(0.5) # required to let file creation happen log_text = applog.get_text_from_log() assert "Top level log configuration" in log_text assert "Sub process setup configuration" in log_text assert "Sub process debug log info" in log_text applog.explicit_log_close()
def simulate_all_main(self, qtbot, request, filename=None, update_time_interval=0, history_size=3000): """ Setup the controller the same way the scripts/Application does at every setup. Ensure that the teardown is in place regardless of test result. Use the All controller to display six lines of data from the temperature logger. """ assert applog.delete_log_file_if_exists() == True geometry = [100, 100, 800, 500] main_logger = applog.MainLogger() app_control = control.AllController(main_logger.log_queue, geometry=geometry, update_time_interval=update_time_interval, history_size=history_size, filename=filename, device_name="AllValueZMQ") qtbot.addWidget(app_control.form) def control_close(): app_control.close() main_logger.close() applog.explicit_log_close() request.addfinalizer(control_close) return app_control
def simulate_all_main(self, qtbot, request, filename=None, update_time_interval=0, history_size=3000): """ Setup the controller the same way the scripts/Application does at every setup. Ensure that the teardown is in place regardless of test result. Use the All controller to display six lines of data from the temperature logger. """ assert applog.delete_log_file_if_exists() == True geometry = [100, 100, 800, 500] main_logger = applog.MainLogger() app_control = control.AllController( main_logger.log_queue, geometry=geometry, update_time_interval=update_time_interval, history_size=history_size, filename=filename, device_name="AllValueZMQ") qtbot.addWidget(app_control.form) def control_close(): app_control.close() main_logger.close() applog.explicit_log_close() request.addfinalizer(control_close) return app_control
def test_log_file_is_created(self): assert applog.delete_log_file_if_exists() == True main_logger = applog.MainLogger() main_logger.close() time.sleep(0.5) # required to let file creation happen assert applog.log_file_created() == True applog.explicit_log_close()
def test_log_file_has_entries(self): assert applog.delete_log_file_if_exists() == True main_logger = applog.MainLogger() main_logger.close() time.sleep(0.5) # required to let file creation happen log_text = applog.get_text_from_log() assert "Top level log configuration" in log_text applog.explicit_log_close()
def build_sub_process(self, request, delay_time=None): """ Setup the logger, the device inside the sub process, ensure the logging is closed correctly on exit. """ assert applog.delete_log_file_if_exists() == True main_logger = applog.MainLogger() sub_proc = wrapper.SubProcess(main_logger.log_queue, delay_time=delay_time) def close_sub_proc(): sub_proc.close() main_logger.close() applog.explicit_log_close() request.addfinalizer(close_sub_proc) start_wait = 1.0 log.debug("Wait %s for sub process to start", start_wait) time.sleep(start_wait) return sub_proc
def simulate_main(self, qtbot, request): """ Setup the controller the same way the scripts/Application does at every setup. Ensure that the teardown is in place regardless of test result. """ assert applog.delete_log_file_if_exists() == True main_logger = applog.MainLogger() app_control = control.Controller(main_logger.log_queue) qtbot.addWidget(app_control.form) def control_close(): app_control.close() main_logger.close() applog.explicit_log_close() request.addfinalizer(control_close) return app_control
def simulate_dual_main(self, qtbot, request): """ Setup the controller the same way the scripts/Application does at every setup. Ensure that the teardown is in place regardless of test result. Use the Dual controller to display two lines of data. """ assert applog.delete_log_file_if_exists() == True main_logger = applog.MainLogger() app_control = control.DualController(main_logger.log_queue, device_name="DualTriValueZMQ") qtbot.addWidget(app_control.form) def control_close(): app_control.close() main_logger.close() applog.explicit_log_close() request.addfinalizer(control_close) return app_control
def test_queue_manual_empty_for_increased_coverage(self): """ Manually setup the wrapper process, then change the queue state manually to induce exception. """ assert applog.delete_log_file_if_exists() == True main_logger = applog.MainLogger() sub_proc = wrapper.SubProcess(main_logger.log_queue, delay_time=1.0) start_wait = 1.0 log.debug("Manual Wait %s for sub process to start", start_wait) time.sleep(start_wait) # Put onto the control queue manually, then close the process to trigger # the full queue exception. try: sub_proc.control.put(None, block=True, timeout=1.0) except: log.critical("Can't put poison pill before close") sub_proc.close() # Wait for the sub process to close, then attempt to read in order to # trigger the queue empty exception time.sleep(1) empty_found = False while not empty_found: try: get_result = sub_proc.results.get(block=True, timeout=0.1) except Queue.Empty: empty_found = True result = sub_proc.read() main_logger.close() applog.explicit_log_close()
def test_log_file_has_sub_process_entries(self): """ This test documents the alternative: slurp the log results back in from the log file and then do the text matches. """ assert applog.delete_log_file_if_exists() == True main_logger = applog.MainLogger() log_queue = main_logger.log_queue sub_proc = multiprocessing.Process(target=self.worker_process, args=(log_queue,)) sub_proc.start() time.sleep(1.0) # make sure the process has enough time to emit main_logger.close() time.sleep(0.5) # required to let file creation happen log_text = applog.get_text_from_log() assert "Top level log configuration" in log_text assert "Sub process setup configuration" in log_text assert "Sub process debug log info" in log_text applog.explicit_log_close()