def log_level_test(self, file_expected, console_expected, file_level, console_level): """Test results from a specific log test.""" log.set_log_level(file_level, console_level) self.logMessages() # Get file output f = open(self.logfile, 'r') lines = f.readlines() f.close() # The first line is the output message from # log.set_log_file(self.logfile, log.file_logging_level) # so we want the slice after this file_result = strip_log(lines)[1:] console_result = self.console.getvalue().strip().split('\n')[1:] file_expected = strip_log(file_expected.split('\n')) console_expected = console_expected.split('\n') self.assertEqual(file_result, file_expected) self.assertEqual(console_result, console_expected)
def test_log_json(self): file_level = 'debug' console_level = 'debug' log.set_log_level(file_level, console_level) dic = {"eggs": "ham"} log.log_json(dic, level=logging.DEBUG) # Get file output f = open(self.logfile, 'r') lines = f.readlines() f.close() file_expected = '''|Logfile is '%s' with logging level of DEBUG, console logging level is DEBUG |JS*N{"eggs": "ham"}''' % self.logfile console_expected = '''Logfile is '%s' with logging level of DEBUG, console logging level is DEBUG JS*N{"eggs": "ham"}''' % self.logfile # The first line is the output message from # log.set_log_file(self.logfile, log.file_logging_level) # so we want the slice after this file_result = strip_log(lines)[1:] console_result = self.console.getvalue().strip().split('\n')[1:] file_expected = strip_log(file_expected.split('\n')) console_expected = console_expected.split('\n') #print "file_result", file_result #print "console_result", console_result self.assertEqual(file_result, file_expected) self.assertEqual(console_result, console_expected)
def test_log_json(self): file_level = 'debug' console_level = 'debug' log.set_log_level(file_level, console_level) dic = {"eggs":"ham"} log.log_json(dic, level=logging.DEBUG) # Get file output f = open(self.logfile, 'r') lines = f.readlines() f.close() file_expected = '''|Logfile is '%s' with logging level of DEBUG, console logging level is DEBUG |JS*N{"eggs": "ham"}''' % self.logfile console_expected = '''Logfile is '%s' with logging level of DEBUG, console logging level is DEBUG JS*N{"eggs": "ham"}''' % self.logfile # The first line is the output message from # log.set_log_file(self.logfile, log.file_logging_level) # so we want the slice after this file_result = strip_log(lines)[1:] console_result = self.console.getvalue().strip().split('\n')[1:] file_expected = strip_log(file_expected.split('\n')) console_expected = console_expected.split('\n') #print "file_result", file_result #print "console_result", console_result self.assertEqual(file_result, file_expected) self.assertEqual(console_result, console_expected)
def tearDown(self): # Set everything back to the way it was log.default_to_console = self.default_to_console_orig log.allow_level_override = self.allow_level_override_orig log.set_log_level(logging.getLevelName(self.file_level_orig), logging.getLevelName(self.console_level_orig)) log.set_log_file(self.log_filename_orig) # ..and stdout! sys.stdout = sys.__stdout__ # Remove the temporary logfile os.remove(self.logfile)
def test_set_log_level_no_effect(self): """ Test set_log_level where it is expected to have no effect. i.e. levels set programmatically elsewhere """ log.allow_level_override = False log.console_logging_level = log.WARNING log.file_logging_level = log.INFO log.set_log_level(level='debug', console_level='critical') self.assertNotEqual(log.console_logging_level, log.CRITICAL) self.assertNotEqual(log.file_logging_level, log.DEBUG)
def big_array(elements, dtype=float): # set up the logging log_filename = os.path.join(DIRPATH, 'log-0-' + str(elements) + '.txt') log.log_filename = log_filename log.remove_log_file() log.set_log_level('DEBUG') log.resource_usage(tag=log.INITIAL_J) array_mem = numpy.zeros([elements], dtype=dtype) log.resource_usage(tag=log.FINAL_J) dic = {"actual_mem MB": array_mem.nbytes / estimator.MB2B, "elements": elements} log.log_json(dic, log.DEBUG)
def big_array(elements, dtype=float): # set up the logging log_filename = os.path.join(DIRPATH, 'log-0-' + str(elements) + '.txt') log.log_filename = log_filename log.remove_log_file() log.set_log_level('DEBUG') log.resource_usage(tag=log.INITIAL_J) array_mem = numpy.zeros([elements], dtype=dtype) log.resource_usage(tag=log.FINAL_J) dic = { "actual_mem MB": array_mem.nbytes / estimator.MB2B, "elements": elements } log.log_json(dic, log.DEBUG)