def test_log_capture_fixture_does_not_see_sub_process_entries( self, caplog): """ This test is about documenting the expected behavior. It took days of effort to determine that the logging is behaving as expected, but the pytest capture fixtures does not seem to be able to record those values. """ 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 = caplog.text() assert "Top level log configuration" in log_text assert "Sub process setup configuration" not in log_text assert "Sub process debug log info" not in log_text 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()
def test_direct_device_is_available(self, caplog): device = devices.SimulatedPM100() result = device.read() assert result != 0 assert result != None applog.explicit_log_close()
def test_slapchop_direct_device_is_available(self, caplog): device = devices.SlapChopDevice() result = device.read() assert result != 0 assert result != None applog.explicit_log_close()
def test_direct_device_is_available(self, caplog): device = devices.ThorlabsMeter() result = device.read() assert result != 0 # negative is ok assert result != None applog.explicit_log_close()
def test_slapchop_values_change(self, caplog): device = devices.SlapChopDevice() first_result = device.read() second_result = device.read() assert first_result != second_result applog.explicit_log_close()
def test_zmq_single_value_is_returned(self, caplog): """ This requires the publisher exists in a separate process. """ device = devices.TriValueZMQ() result = device.read() assert result != 0 applog.explicit_log_close()
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_zmq_dual_read_has_two_values(self, caplog): """ This requires the publisher exists in a separate process. """ device = devices.DualTriValueZMQ() temperature, power = device.read() assert temperature != 0 assert power != 0 applog.explicit_log_close()
def test_zmq_device_is_available(self, caplog): """ This requires the publisher exists in a separate process. """ device = devices.TriValueZMQ() result = device.read() assert result != 0 assert result != None applog.explicit_log_close()
def test_direct_device_looks_real(self): device = devices.ThorlabsMeter() result = device.read() assert result != 0 assert result != None new_result = device.read() assert result != new_result applog.explicit_log_close()
def test_direct_device_randomized(self): device = devices.SimulatedPM100() result = device.read() assert result != 0 assert result != None new_result = device.read() assert result != new_result 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 test_sleep_factor_slows_down_reads(self): device = devices.SimulatedPM100(sleep_factor=1.0) result = device.read() assert result != 0 assert result != None start_time = time.time() new_result = device.read() cease_time = time.time() time_diff = cease_time - start_time assert time_diff >= 1.0 assert result != new_result applog.explicit_log_close()
def test_zmq_all_reads_has_six_values(self, caplog): """ This requires the publisher exists in a separate process. """ device = devices.AllValueZMQ() # CCD temp, laser temp, laser power, yellow therm, blue therm, # amps c, lt, lp, yt, bt, amp = device.read() assert c != None assert lt != None assert lp != None assert yt != None assert bt != None assert amp != None print "Full read: %s" % device.read() applog.explicit_log_close()
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_capture_fixture_does_not_see_sub_process_entries(self, caplog): """ This test is about documenting the expected behavior. It took days of effort to determine that the logging is behaving as expected, but the pytest capture fixtures does not seem to be able to record those values. """ 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 = caplog.text() assert "Top level log configuration" in log_text assert "Sub process setup configuration" not in log_text assert "Sub process debug log info" not in log_text 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()
def test_direct_logging_is_available(self, caplog): device = devices.SimulatedPM100() assert "SimulatedPM100 setup" in caplog.text() applog.explicit_log_close()
def control_close(): app_control.close() main_logger.close() applog.explicit_log_close()
def test_direct_logging_is_available(self, caplog): device = devices.ThorlabsMeter() assert "ThorlabsMeter setup" in caplog.text() applog.explicit_log_close()
def test_zmq_wrapper_device_has_read(self, caplog): device = devices.TriValueZMQ() assert "TriValueZMQ setup" in caplog.text() applog.explicit_log_close()
def test_log_capture_fixture_can_read_top_level_log(self, caplog): main_logger = applog.MainLogger() main_logger.close() assert "Top level log configuration" in caplog.text() applog.explicit_log_close()
def close_sub_proc(): sub_proc.close() main_logger.close() applog.explicit_log_close()
def test_slapchop_direct_logging_is_available(self, caplog): device = devices.SlapChopDevice() assert "SlapChopDevice setup" in caplog.text() applog.explicit_log_close()