コード例 #1
0
    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()
コード例 #2
0
    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()
コード例 #3
0
    def test_direct_device_is_available(self, caplog):
        device = devices.SimulatedPM100()
        result = device.read()

        assert result != 0
        assert result != None

        applog.explicit_log_close()
コード例 #4
0
    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()
コード例 #5
0
    def test_direct_device_is_available(self, caplog):
        device = devices.SimulatedPM100()
        result = device.read()

        assert result != 0
        assert result != None

        applog.explicit_log_close()
コード例 #6
0
    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()
コード例 #7
0
    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()
コード例 #8
0
    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()
コード例 #9
0
    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()
コード例 #10
0
    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()
コード例 #11
0
    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()
コード例 #12
0
    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()
コード例 #13
0
    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()
コード例 #14
0
    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()
コード例 #15
0
    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()
コード例 #16
0
    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()
コード例 #17
0
    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()
コード例 #18
0
    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()
コード例 #19
0
    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()
コード例 #20
0
    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()
コード例 #21
0
    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()
コード例 #22
0
    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()
コード例 #23
0
    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()
コード例 #24
0
    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()
コード例 #25
0
    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()
コード例 #26
0
    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()
コード例 #27
0
    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()
コード例 #28
0
    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()
コード例 #29
0
ファイル: test_wrapper.py プロジェクト: rajeevyadav/FastPM100
    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()
コード例 #30
0
    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()
コード例 #31
0
 def test_direct_logging_is_available(self, caplog):
     device = devices.SimulatedPM100()
     assert "SimulatedPM100 setup" in caplog.text()
     applog.explicit_log_close()
コード例 #32
0
 def control_close():
     app_control.close()
     main_logger.close()
     applog.explicit_log_close()
コード例 #33
0
 def test_direct_logging_is_available(self, caplog):
     device = devices.ThorlabsMeter()
     assert "ThorlabsMeter setup" in caplog.text()
     applog.explicit_log_close()
コード例 #34
0
 def control_close():
     app_control.close()
     main_logger.close()
     applog.explicit_log_close()
コード例 #35
0
 def test_zmq_wrapper_device_has_read(self, caplog):
     device = devices.TriValueZMQ()
     assert "TriValueZMQ setup" in caplog.text()
     applog.explicit_log_close()
コード例 #36
0
    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()
コード例 #37
0
    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()
コード例 #38
0
 def close_sub_proc():
     sub_proc.close()
     main_logger.close()
     applog.explicit_log_close()
コード例 #39
0
 def test_zmq_wrapper_device_has_read(self, caplog):
     device = devices.TriValueZMQ()
     assert "TriValueZMQ setup" in caplog.text()
     applog.explicit_log_close()
コード例 #40
0
 def test_slapchop_direct_logging_is_available(self, caplog):
     device = devices.SlapChopDevice()
     assert "SlapChopDevice setup" in caplog.text()
     applog.explicit_log_close()
コード例 #41
0
ファイル: test_wrapper.py プロジェクト: rajeevyadav/FastPM100
 def close_sub_proc():
     sub_proc.close()
     main_logger.close()
     applog.explicit_log_close()
コード例 #42
0
 def test_slapchop_direct_logging_is_available(self, caplog):
     device = devices.SlapChopDevice()
     assert "SlapChopDevice setup" in caplog.text()
     applog.explicit_log_close()
コード例 #43
0
 def test_direct_logging_is_available(self, caplog):
     device = devices.SimulatedPM100()
     assert "SimulatedPM100 setup" in caplog.text()
     applog.explicit_log_close()