Commit 0c3c2b2c authored by Huihui, Jonathan's avatar Huihui, Jonathan
Browse files

add critical test, clear up messages

parent f3c60e96
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -42,10 +42,11 @@ class LogzTestCase(unittest.TestCase):
        # create a DB connection
        with DBPG() as data_base:
            # use the logger in the db to log some info
            data_base.logger.info("THIS IS TEST 1!")
            data_base.logger.info("THIS IS TEST 2!")
            data_base.logger.debug("THIS IS TEST 3!")
            data_base.logger.error("THIS IS TEST 4!")
            data_base.logger.info("THIS IS TEST 1! (info)")
            data_base.logger.info("<-- Info test.")
            data_base.logger.debug("<-- Debug test.")
            data_base.logger.error("<-- Error test.")
            data_base.logger.critical("<-- Critical test.")
            # verify that the log file is indeed a file
            self.assertTrue(os.path.isfile("./test.log"))
            # verify that the file exists
@@ -62,26 +63,30 @@ class LogzTestCase(unittest.TestCase):
            found_t2 = False
            found_t3 = False
            found_t4 = False
            found_t5 = False
            # iterate through the file's lines
            for line in file.readlines():
                # if any of the test logs are found, record their existance
                if "THIS IS TEST 1!" in line:
                if "THIS IS TEST 1! (info)" in line:
                    found_t1 = True
                elif "THIS IS TEST 2!" in line and "INFO" in line:
                elif "<-- Info test." in line and "INFO" in line:
                    found_t2 = True
                elif "THIS IS TEST 3!" in line and "DEBUG" in line:
                elif "<-- Debug test." in line and "DEBUG" in line:
                    found_t3 = True
                elif "THIS IS TEST 4!" in line and "ERROR" in line:
                elif "<-- Error test." in line and "ERROR" in line:
                    found_t4 = True
                elif "<-- Critical test." in line and "CRITICAL" in line:
                    found_t5 = True
            # validate that all the test logs were found
            self.assertTrue(found_t1 and found_t2 and found_t3 and found_t4)
            self.assertTrue(found_t1 and found_t2 and found_t3 and found_t4 and found_t5)

        # create a path for the standalone log file
        path = "./standalone.log"
        # create a logger to test its abilities standalone
        logger = create_logger(path, 'a', "utf-8")
        # log some info
        logger.info("THIS IS TEST 5!")
        log_str = "THIS IS TEST 5! (info level)"
        logger.info(log_str)
        # verify that a the path is a file
        self.assertTrue(os.path.isfile(path))
        # verify that the file exists
@@ -93,7 +98,7 @@ class LogzTestCase(unittest.TestCase):
        # verify that the data from the logger is in the file
        with open(path, 'r', encoding="utf-8") as file:
            line = file.readline()
            self.assertTrue("THIS IS TEST 5" in line)
            self.assertTrue(log_str in line)
            self.assertTrue("INFO" in line)
            file.close()