def test_get_option_location(self): """ Test the get option location method in configfile module """ config_directory = get_test_config('config-test1.d') location = get_test_config('config-test1.d/00-test.ini') opt_location = configfile.get_option_location( 'first_opt', 'Common', config_directory=config_directory) self.assertEqual( location, opt_location, "Didn't get the correct location for first_opt:" + "got %s expected %s" % (opt_location, location)) location = get_test_config('config-test1.d/10-test.ini') opt_location = configfile.get_option_location( 'second_opt', 'Common', config_directory=config_directory) self.assertEqual( location, opt_location, "Didn't get the correct location for second_opt:" + "got %s expected %s" % (opt_location, location)) location = None opt_location = configfile.get_option_location( 'missing_opt', 'Common', config_directory=config_directory) self.assertEqual( location, opt_location, "Didn't get the correct location for missing_opt:" + "got %s expected None" % (opt_location))
def test_get_option_location(self): """ Test the get option location method in configfile module """ config_directory = get_test_config('config-test1.d') location = get_test_config('config-test1.d/00-test.ini') opt_location = configfile.get_option_location('first_opt', 'Common', config_directory=config_directory) self.assertEqual(location, opt_location, "Didn't get the correct location for first_opt:" + "got %s expected %s" % (opt_location, location)) location = get_test_config('config-test1.d/10-test.ini') opt_location = configfile.get_option_location('second_opt', 'Common', config_directory=config_directory) self.assertEqual(location, opt_location, "Didn't get the correct location for second_opt:" + "got %s expected %s" % (opt_location, location)) location = None opt_location = configfile.get_option_location('missing_opt', 'Common', config_directory=config_directory) self.assertEqual(location, opt_location, "Didn't get the correct location for missing_opt:" + "got %s expected None" % (opt_location))
def log(self, mesg, *args, **kwargs): """ Generate a log message if option and section are given then the file that generated the error is added to log message Arguments: mesg - message to add to default log message args - arguments to substitute into mesg Keyword Arguments: option - option that caused the log message to be created section - the section that the option given above is location in level - optional log level for message, should be a level from logging, defaults to logging.DEBUG if none given exception - if True, adds exception information to log file """ log_level = kwargs.get('level', logging.DEBUG) exception = kwargs.get('exception', False) message = "" if 'option' in kwargs and 'section' in kwargs: file_location = configfile.get_option_location( kwargs['option'], kwargs['section']) if file_location is not None: message = "Option '%s' in section '%s' located in %s: " % ( kwargs['option'], kwargs['section'], file_location) message += "\n" + " " * 9 + ("\n" + " " * 9).join( mesg.split("\n")) else: message += mesg else: message += mesg self.logger.log(log_level, message, *args, exc_info=exception)
def log(self, mesg, **kwargs): """ Generate a log message if option and section are given then the file that generated the error is added to log message Arguments: mesg - message to add to default log message Keyword Arguments: option - option that caused the log message to be created section - the section that the option given above is location in level - optional log level for message, should be a level from logging, defaults to logging.DEBUG if none given exception - if True, adds exception information to log file """ log_level = kwargs.get('level', logging.DEBUG) exception = kwargs.get('exception', False) message = "" if 'option' in kwargs and 'section' in kwargs: file_location = configfile.get_option_location(kwargs['option'], kwargs['section']) if file_location is not None: message = "Option '%s' in section '%s' located in %s: " % (kwargs['option'], kwargs['section'], file_location) message += mesg self.logger.log(log_level, message, exc_info=exception)