Loading test/test.py +45 −0 Original line number Diff line number Diff line Loading @@ -2,8 +2,11 @@ # -*- coding: utf-8 -*- """Unit test common functionality.""" import unittest import os from unittest.case import _AssertWarnsContext from common.database import Database from common.mixins.postgres import PostgresMixin from common.logz import create_logger class DBPG(Database, PostgresMixin): Loading @@ -20,6 +23,48 @@ class PostgresTestCase(unittest.TestCase): with DBPG() as db: print(db.query("SELECT * FROM test_table")) class LogzTestCase(unittest.TestCase): def setUp(self) -> None: return super().setUp() def test_create_logger(self): with DBPG() as db: db.logger.info("THIS IS TEST 1!") db.logger.info("THIS IS TEST 2!") db.logger.debug("THIS IS TEST 3!") db.logger.error("THIS IS TEST 4!") self.assertTrue(os.path.isfile("./test.log")) self.assertTrue(os.path.exists("./test.log")) file_size = os.path.getsize("./test.log") self.assertTrue(file_size > 0 ) with open("./test.log") as file: found_t1 = False found_t2 = False found_t3 = False found_t4 = False for line in file.readlines(): if "THIS IS TEST 1!" in line: found_t1 = True elif "THIS IS TEST 2!" in line and "INFO" in line: found_t2 = True elif "THIS IS TEST 3!" in line and "DEBUG" in line: found_t3 = True elif "THIS IS TEST 4!" in line and "ERROR" in line: found_t4 = True self.assertTrue(found_t1 and found_t2 and found_t3 and found_t4) path = "standalone.log" logger = create_logger(file_out=path, mode='w', encoding="utf-8") logger.info("THIS IS TEST 5!") logger.info("THIS IS TEST 5!") logger.info("THIS IS TEST 5!") self.assertTrue(os.path.isfile(path)) self.assertTrue(os.path.exists(path)) file_size = os.path.getsize(path) self.assertGreater(file_size, 0) if __name__ == "__main__": unittest.main(verbosity=2) Loading
test/test.py +45 −0 Original line number Diff line number Diff line Loading @@ -2,8 +2,11 @@ # -*- coding: utf-8 -*- """Unit test common functionality.""" import unittest import os from unittest.case import _AssertWarnsContext from common.database import Database from common.mixins.postgres import PostgresMixin from common.logz import create_logger class DBPG(Database, PostgresMixin): Loading @@ -20,6 +23,48 @@ class PostgresTestCase(unittest.TestCase): with DBPG() as db: print(db.query("SELECT * FROM test_table")) class LogzTestCase(unittest.TestCase): def setUp(self) -> None: return super().setUp() def test_create_logger(self): with DBPG() as db: db.logger.info("THIS IS TEST 1!") db.logger.info("THIS IS TEST 2!") db.logger.debug("THIS IS TEST 3!") db.logger.error("THIS IS TEST 4!") self.assertTrue(os.path.isfile("./test.log")) self.assertTrue(os.path.exists("./test.log")) file_size = os.path.getsize("./test.log") self.assertTrue(file_size > 0 ) with open("./test.log") as file: found_t1 = False found_t2 = False found_t3 = False found_t4 = False for line in file.readlines(): if "THIS IS TEST 1!" in line: found_t1 = True elif "THIS IS TEST 2!" in line and "INFO" in line: found_t2 = True elif "THIS IS TEST 3!" in line and "DEBUG" in line: found_t3 = True elif "THIS IS TEST 4!" in line and "ERROR" in line: found_t4 = True self.assertTrue(found_t1 and found_t2 and found_t3 and found_t4) path = "standalone.log" logger = create_logger(file_out=path, mode='w', encoding="utf-8") logger.info("THIS IS TEST 5!") logger.info("THIS IS TEST 5!") logger.info("THIS IS TEST 5!") self.assertTrue(os.path.isfile(path)) self.assertTrue(os.path.exists(path)) file_size = os.path.getsize(path) self.assertGreater(file_size, 0) if __name__ == "__main__": unittest.main(verbosity=2)