コード例 #1
0
    def test_info_message(self):
        """
        Tests the .info method
        """
        with mock.patch.dict(os.environ,
                             {"LOG_DIRECTORY": self.temp_dir.path}):
            with LogCapture() as capture:
                logger = Logger(name="test_logger", filename="logger.txt")
                logger.info("test message")

                capture.check(("test_logger", "INFO", "test message"))
コード例 #2
0
def main():
    logger = Logger(name="main.log", filename="main.log")
    logger.info("Started hardware main.py")
    if os.environ["HARDWARE_TYPE"] == "commPi":
        logger.info("CommunicationsPi")
        handleComm()
    elif os.environ["HARDWARE_TYPE"] == "sensePi":
        logger.info("SensePi")
        handleSense()
    elif os.environ["HARDWARE_TYPE"] == "gpsPi":
        logger.info("gpsPi")
        handleGps()
    else:
        logger.info("Local Django Server")
        handleLocal()
コード例 #3
0
    def test_info_message_with_print(self, mock_print=mock.MagicMock()):
        """
        Tests the .info method
        """
        with mock.patch.dict(os.environ, {
                "LOG_DIRECTORY": self.temp_dir.path,
                "SHOW_LOGS": "True"
        }):
            with LogCapture() as capture:
                logger = Logger(name="test_logger", filename="logger.txt")
                logger.info("test message")

                self.assertTrue(
                    mock_print.mock_calls == [mock.call("test message")])

                capture.check(("test_logger", "INFO", "test message"))