diff --git a/pungi/phases/base.py b/pungi/phases/base.py index f4b62ff1..6c83fa31 100644 --- a/pungi/phases/base.py +++ b/pungi/phases/base.py @@ -162,12 +162,14 @@ class PhaseLoggerMixin(object): """ def __init__(self, *args, **kwargs): super(PhaseLoggerMixin, self).__init__(*args, **kwargs) - self.logger = logging.getLogger(self.name.upper()) - self.logger.setLevel(logging.DEBUG) - format = "%(asctime)s [%(name)-16s] [%(levelname)-8s] %(message)s" - import copy - for handler in self.compose._logger.handlers: - hl = copy.copy(handler) - hl.setFormatter(logging.Formatter(format, datefmt="%Y-%m-%d %H:%M:%S")) - hl.setLevel(logging.DEBUG) - self.logger.addHandler(hl) + self.logger = None + if self.compose._logger and self.compose._logger.handlers: + self.logger = logging.getLogger(self.name.upper()) + self.logger.setLevel(logging.DEBUG) + format = "%(asctime)s [%(name)-16s] [%(levelname)-8s] %(message)s" + import copy + for handler in self.compose._logger.handlers: + hl = copy.copy(handler) + hl.setFormatter(logging.Formatter(format, datefmt="%Y-%m-%d %H:%M:%S")) + hl.setLevel(logging.DEBUG) + self.logger.addHandler(hl) diff --git a/tests/test_config_validate_script.py b/tests/test_config_validate_script.py new file mode 100644 index 00000000..14d6536f --- /dev/null +++ b/tests/test_config_validate_script.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +import unittest +import mock +import os +import subprocess +import sys + + +HERE = os.path.abspath(os.path.dirname(__file__)) +BINDIR = os.path.join(HERE, '../bin') +PUNGI_CONFIG_VALIDATE = os.path.join(BINDIR, 'pungi-config-validate') + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) + +from tests import helpers + + +class ConfigValidateScriptTest(helpers.PungiTestCase): + + @mock.patch('kobo.shortcuts.run') + def test_validate_dummy_config(self, run): + DUMMY_CONFIG = os.path.join(HERE, 'data/dummy-pungi.conf') + p = subprocess.Popen([PUNGI_CONFIG_VALIDATE, DUMMY_CONFIG], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + (stdout, stderr) = p.communicate() + self.assertEqual(0, p.returncode) + self.assertEqual('', stdout) + self.assertEqual('', stderr) + +if __name__ == '__main__': + unittest.main()