コード例 #1
0
 def test_fileLoggerAppendFileTest(self):
     file_logger = FileLogger("", True, MessageType.INFORMATION,
                              "WriteToExistingFileLogger")
     file_logger.log_message("This is a test to write to an existing file.",
                             None, MessageType.WARNING)
     # os.remove(file_logger.get_file_path())
     self.assertTrue(path.exists(file_logger.get_file_path()))
コード例 #2
0
 def test_FileLoggerCatchThrownException(self):
     file_logger = FileLogger("", True, "FileLoggerCatchThrownException",
                              MessageType.GENERIC)
     file_logger.set_file_path("<>")
     file_logger.log_message(MessageType.GENERIC, "test throws error")
     os.remove(file_logger.get_file_path())
     self.assertTrue(path.exists(file_logger.get_file_path()))
コード例 #3
0
 def test_FileLoggerLogMessage(self):
     file_logger = FileLogger("", True, "FileLoggerLogMessage")
     file_logger.log_message("Test to ensure LogMessage works as expected.")
     self.assertTrue(
         self.Test_Message
         in self.read_text_file(file_logger.get_file_path()),
         "Expected Log Message to be contained in log.")
     os.remove(file_logger.get_file_path())
     self.assertTrue(path.exists(file_logger.get_file_path()))
コード例 #4
0
 def test_WriteToExistingFileLogger(self):
     file_logger = FileLogger("", True, "WriteToExistingFileLogger",
                              MessageType.GENERIC)
     file_logger.log_message("This is a test.", None, MessageType.WARNING)
     file_logger.log_message(
         MessageType.WARNING,
         "This is a test to write to an existing file.")
     os.remove(file_logger.get_file_path())
     self.assertTrue(path.exists(file_logger.get_file_path()))
コード例 #5
0
 def test_FileLoggerConstructorCreateDirectory(self):
     message = "Test to ensure that the file in the created directory can be written to."
     file_logger = FileLogger(LoggingConfig().get_log_directory(), True,
                              "FileLoggerCreateDirectoryDelete",
                              MessageType.GENERIC)
     file_logger.log_message(
         MessageType.WARNING.value,
         "Test to ensure that the file in the created directory can be written to."
     )
     file = file_logger.get_file_path()
     actual_message = self.read_text_file(file.getCanonicalPath())
     self.assertTrue(
         message in actual_message, "Expected '" + message + "' but got '" +
         actual_message + "' for: " + file.getCanonicalPath())
     os.remove(file)
     self.assertTrue(path.exists(file_logger.get_file_path()))
コード例 #6
0
    def Test_SuspendLogger(self):
        # Start logging
        file_logger = FileLogger(
            True,
            LoggingConfig().get_log_directory(),
            self.get_file_name("TestHierarchicalTxtFileLogger", "txt"),
            MessageType.GENERIC.value)
        file_logger.set_logging_level(MessageType.VERBOSE)
        file_logger.log_message(MessageType.VERBOSE, "HellO")

        # Suspend logging
        file_logger.suspend_logging()
        file_logger.log_message(MessageType.ERROR, "GoodByE")

        # Continue logging
        file_logger.continue_logging()
        file_logger.log_message(MessageType.VERBOSE, "BacK")

        # Get the log file content
        log_contents = self.read_text_file(file_logger.get_file_path())

        # Verify that logging was active
        hello_found = "HellO" in log_contents
        self.assertTrue(hello_found, "'HellO' was not found.  Logging Failed")

        # Verify that logging was suspended
        goodbye_found = "GoodByE" in log_contents
        self.assertFalse(
            goodbye_found,
            "'GoodByE' was found when it should not be written.  Logging Failed"
        )

        # Verify that logging was active
        back_found = "BacK" in log_contents
        self.assertTrue(back_found, "'BacK' was not found.  Logging Failed")

        os.remove(file_logger.get_file_path())
        self.assertTrue(path.exists(file_logger.get_file_path()))
コード例 #7
0
 def test_WriteToFileLogger(self):
     file_logger = FileLogger("", False, "WriteToFileLogger")
     file_logger.log_message(MessageType.WARNING.value,
                             "Hello, this is a test.")
     os.remove(file_logger.get_file_path())
     self.assertTrue(path.exists(file_logger.get_file_path()))