Fix remaining refs to the former config object
Switch notation from value = d.key to value = d.get('key') # in optional cases value = ['key'] # in required cases Unittests for config dictionary make use of mock.patch.dict Change-Id: Ib688dd13e1e3df9a82b3f0377064be8e6c765e55 Closes-Bug: #1301020
This commit is contained in:
parent
70cc26801f
commit
54f816aa1f
|
@ -54,8 +54,8 @@ def init_logging(config, default_config=None):
|
|||
:param config: object with configuration namespace (ex. argparse parser)
|
||||
:keyword default_config: path to a python logging configuration file
|
||||
"""
|
||||
if config.logconfig and os.path.isfile(config.logconfig):
|
||||
logging.config.fileConfig(config.logconfig,
|
||||
if config.get('logconfig') and os.path.isfile(config.get('logconfig')):
|
||||
logging.config.fileConfig(config['logconfig'],
|
||||
disable_existing_loggers=False)
|
||||
elif default_config and os.path.isfile(default_config):
|
||||
logging.config.fileConfig(default_config,
|
||||
|
@ -83,11 +83,11 @@ def log_level(config):
|
|||
|
||||
:param config: object with configuration namespace (ex. argparse parser)
|
||||
"""
|
||||
if config.debug is True:
|
||||
if config.get('debug') is True:
|
||||
return logging.DEBUG
|
||||
elif config.verbose is True:
|
||||
elif config.get('verbose') is True:
|
||||
return logging.DEBUG
|
||||
elif config.quiet is True:
|
||||
elif config.get('quiet') is True:
|
||||
return logging.WARNING
|
||||
else:
|
||||
return logging.INFO
|
||||
|
@ -105,13 +105,13 @@ def get_debug_formatter(config):
|
|||
|
||||
:param config: object with configuration namespace (ex. argparse parser)
|
||||
"""
|
||||
if config.debug is True:
|
||||
if config.get('debug') is True:
|
||||
return DebugFormatter('%(pathname)s:%(lineno)d: %(levelname)-8s '
|
||||
'%(message)s')
|
||||
elif config.verbose is True:
|
||||
elif config.get('verbose') is True:
|
||||
return logging.Formatter(
|
||||
'%(name)-30s: %(levelname)-8s %(message)s')
|
||||
elif config.quiet is True:
|
||||
elif config.get('quiet') is True:
|
||||
return logging.Formatter('%(message)s')
|
||||
else:
|
||||
return logging.Formatter('%(message)s')
|
||||
|
|
|
@ -26,28 +26,32 @@ class TestLoggingSetup(utils.TestCase):
|
|||
"""Logging Setup tests."""
|
||||
|
||||
def test_logging_default_info(self):
|
||||
config = mock.MagicMock(logconfig=None)
|
||||
logging.init_logging(config)
|
||||
self.assertEqual(stdlib_logging.getLogger().level,
|
||||
stdlib_logging.INFO)
|
||||
config = {}
|
||||
with mock.patch.dict(config, {'logconfig': None}):
|
||||
logging.init_logging(config)
|
||||
self.assertEqual(stdlib_logging.getLogger().level,
|
||||
stdlib_logging.INFO)
|
||||
|
||||
def test_logging_debug_flag(self):
|
||||
config = mock.MagicMock(logconfig=None, debug=True)
|
||||
logging.init_logging(config)
|
||||
self.assertEqual(stdlib_logging.getLogger().level,
|
||||
stdlib_logging.DEBUG)
|
||||
config = {}
|
||||
with mock.patch.dict(config, {'logconfig': None, 'debug': True}):
|
||||
logging.init_logging(config)
|
||||
self.assertEqual(stdlib_logging.getLogger().level,
|
||||
stdlib_logging.DEBUG)
|
||||
|
||||
def test_logging_verbose_flag(self):
|
||||
config = mock.MagicMock(logconfig=None, verbose=True)
|
||||
logging.init_logging(config)
|
||||
self.assertEqual(stdlib_logging.getLogger().level,
|
||||
stdlib_logging.DEBUG)
|
||||
config = {}
|
||||
with mock.patch.dict(config, {'logconfig': None, 'verbose': True}):
|
||||
logging.init_logging(config)
|
||||
self.assertEqual(stdlib_logging.getLogger().level,
|
||||
stdlib_logging.DEBUG)
|
||||
|
||||
def test_logging_quiet_flag(self):
|
||||
config = mock.MagicMock(logconfig=None, quiet=True)
|
||||
logging.init_logging(config)
|
||||
self.assertEqual(stdlib_logging.getLogger().level,
|
||||
stdlib_logging.WARN)
|
||||
config = {}
|
||||
with mock.patch.dict(config, {'logconfig': None, 'quiet': True}):
|
||||
logging.init_logging(config)
|
||||
self.assertEqual(stdlib_logging.getLogger().level,
|
||||
stdlib_logging.WARN)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue