示例#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 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
示例#4
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()
示例#5
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()
示例#6
0
    def run(self):
        """ This is the application code that is called by the main
        function. The architectural idea is to have as little code in
        main as possible and create the qapplication here so the
        testing code can function separately with pytest-qt.
        """
        self.app = QtGui.QApplication([])

        self.main_logger = applog.MainLogger()


        title = "%s updated every %s ms for %s reads" \
                % (self.args.device, self.args.update, self.args.size)

        if self.args.controller == "DualController":
            cc = control.DualController
            app_control = cc(self.main_logger.log_queue,
                             device_name="DualTriValueZMQ",
                             history_size=self.args.size,
                             title=title,
                             update_time_interval=self.args.update)

        elif self.args.controller == "AllController":
            cc = control.AllController
            app_control = cc(self.main_logger.log_queue,
                             device_name="AllValueZMQ",
                             history_size=self.args.size,
                             title=title,
                             geometry=self.args.geometry,
                             filename=self.args.filename,
                             update_time_interval=self.args.update)
        else:
            cc = control.Controller
            app_control = cc(self.main_logger.log_queue,
                             device_name=self.args.device,
                             history_size=self.args.size,
                             title=title,
                             update_time_interval=self.args.update)

        app_control.control_exit_signal.exit.connect(self.closeEvent)

        sys.exit(self.app.exec_())
示例#7
0
    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
示例#8
0
    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
示例#9
0
    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
示例#10
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()
示例#11
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()