18
|
1 import unittest
|
|
2 import logging
|
|
3 from commons.core.LoggerFactory import LoggerFactory
|
|
4
|
|
5 class Test_LoggerFactory( unittest.TestCase ):
|
|
6
|
|
7 def test_logger_debug(self):
|
|
8 iLogger = LoggerFactory.createLogger("test")
|
|
9 isMethodExecuted = True
|
|
10 try:
|
|
11 iLogger.debug("message")
|
|
12 except:
|
|
13 isMethodExecuted = False
|
|
14 self.assertTrue(isMethodExecuted)
|
|
15
|
|
16 def test_logger_info(self):
|
|
17 iLogger = LoggerFactory.createLogger("test")
|
|
18 isMethodExecuted = True
|
|
19 try:
|
|
20 iLogger.info("message")
|
|
21 except:
|
|
22 isMethodExecuted = False
|
|
23 self.assertTrue(isMethodExecuted)
|
|
24
|
|
25 def test_logger_warning(self):
|
|
26 iLogger = LoggerFactory.createLogger("test")
|
|
27 isMethodExecuted = True
|
|
28 try:
|
|
29 iLogger.warning("message")
|
|
30 except:
|
|
31 isMethodExecuted = False
|
|
32 self.assertTrue(isMethodExecuted)
|
|
33
|
|
34 def test_logger_error(self):
|
|
35 iLogger = LoggerFactory.createLogger("test")
|
|
36 isMethodExecuted = True
|
|
37 try:
|
|
38 iLogger.error("message")
|
|
39 except:
|
|
40 isMethodExecuted = False
|
|
41 self.assertTrue(isMethodExecuted)
|
|
42
|
|
43 def test_logger_level_debug(self):
|
|
44 iLogger = LoggerFactory.createLogger("test")
|
|
45 LoggerFactory.setLevel(iLogger, 4)
|
|
46 expLevel = logging.DEBUG
|
|
47 obsLevel = iLogger.getEffectiveLevel()
|
|
48 self.assertEquals(expLevel, obsLevel)
|
|
49
|
|
50 def test_logger_level_info(self):
|
|
51 iLogger = LoggerFactory.createLogger("test")
|
|
52 LoggerFactory.setLevel(iLogger, 3)
|
|
53 expLevel = logging.INFO
|
|
54 obsLevel = iLogger.getEffectiveLevel()
|
|
55 self.assertEquals(expLevel, obsLevel)
|
|
56
|
|
57 def test_logger_level_warning(self):
|
|
58 iLogger = LoggerFactory.createLogger("test")
|
|
59 LoggerFactory.setLevel(iLogger, 2)
|
|
60 expLevel = logging.WARNING
|
|
61 obsLevel = iLogger.getEffectiveLevel()
|
|
62 self.assertEquals(expLevel, obsLevel)
|
|
63
|
|
64 def test_logger_level_error(self):
|
|
65 iLogger = LoggerFactory.createLogger("test")
|
|
66 LoggerFactory.setLevel(iLogger, 1)
|
|
67 expLevel = logging.ERROR
|
|
68 obsLevel = iLogger.getEffectiveLevel()
|
|
69 self.assertEquals(expLevel, obsLevel)
|
|
70
|
|
71 def test_logger_default_level(self):
|
|
72 iLogger = LoggerFactory.createLogger("test")
|
|
73 expLevel = logging.ERROR
|
|
74 obsLevel = iLogger.getEffectiveLevel()
|
|
75 self.assertEquals(expLevel, obsLevel)
|
|
76
|
|
77 def test_logger_quiet(self):
|
|
78 iLogger = LoggerFactory.createLogger("test")
|
|
79 LoggerFactory.setLevel(iLogger, 0)
|
|
80 self.assertTrue(iLogger.disabled)
|
|
81
|
|
82 def test_logger_noduplicate_handler(self):
|
|
83 iLogger = LoggerFactory.createLogger("test")
|
|
84 iLogger2 = LoggerFactory.createLogger("test")
|
|
85
|
|
86 expNbHandlers = 1
|
|
87 obsNbHandlers = len(iLogger2.handlers)
|
|
88 self.assertEquals(expNbHandlers, obsNbHandlers)
|
|
89
|
|
90 test_suite = unittest.TestSuite()
|
|
91 test_suite.addTest( unittest.makeSuite( Test_LoggerFactory ) )
|
|
92 if __name__ == "__main__":
|
|
93 unittest.TextTestRunner(verbosity=2).run( test_suite ) |