def setUp(self): self.verbose = False self.testName = "Utility AdmitLogging Class Unit Test" self.logfile = '/tmp/logging_unit_test_%s.log' % os.getpid() self.level = 1 # only need to initialize the logger once since it is a static class if not TestAdmitLogging.setup: Alogging.init(name="test", logfile=self.logfile, level=Alogging.DEBUG) Alogging.addLevelName(15, "TIMING") Alogging.addLevelName(16, "REGRSSION") Alogging.setLevel(self.level) TestAdmitLogging.setup = True
def test_effectiveLevel(self): msg = "unit_test_levels_message" # check that the logging level is what is expected level = Alogging.getEffectiveLevel() self.assertTrue(level == self.level) # set the level to a new value and check again Alogging.setLevel(50) level = Alogging.getEffectiveLevel() self.assertTrue(level == 50) # log an info message which is below the logging level, this message should not appear # in the logs Alogging.info(msg) found = False r = open(self.logfile, 'r') for line in r.readlines(): if msg in line: if(self.verbose): print "\nFound message >", line found = True break r.close() self.assertFalse(found) Alogging.setLevel(self.level) # reset the logging level msg += "2" # log an info message, which is now above the logging level, this message should appear # in the logs Alogging.info(msg) found = False r = open(self.logfile, 'r') for line in r.readlines(): if msg in line: if(self.verbose): print "\nFound message >", line found = True r.close() break self.assertTrue(found)