diff --git a/git_aggregator/config.py b/git_aggregator/config.py index 2a208d7..c1c80b5 100644 --- a/git_aggregator/config.py +++ b/git_aggregator/config.py @@ -104,11 +104,15 @@ def get_repos(config): def load_config(config): """Return repos from a directory and fnmatch. Not recursive. - :param configs: paths to config file - :type path: list + + :param config: paths to config file + :type config: str :returns: expanded config dict item :rtype: iter(dict) """ + if not os.path.exists(config): + raise ConfigException('Unable to find configuration file: %s' % config) + fExt = os.path.splitext(config)[-1] conf = kaptan.Kaptan(handler=fExt.lstrip('.')) conf.import_config(config) diff --git a/tests/test_config.py b/tests/test_config.py index 1896a05..d1a8005 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # © 2015 ACSONE SA/NV # License AGPLv3 (http://www.gnu.org/licenses/agpl-3.0-standalone.html) +import os +import tempfile import unittest import kaptan @@ -218,3 +220,32 @@ def test_load_target_exception(self): self.assertEquals( ex.exception.args[0], '/product_attribute: Target remote oba not defined in remotes.') + + def test_import_config__not_found(self): + with self.assertRaises(ConfigException) as exc: + config.load_config("not_found.yaml") + self.assertEqual( + "Unable to find configuration file: not_found.yaml", + str(exc.exception) + ) + + def test_import_config(self): + data_yaml = """ +/test: + remotes: + oca: https://github.com/test/test.git + merges: + - oca 8.0 + target: oca aggregated_branch_name +""" + + _, config_path = tempfile.mkstemp(suffix='.yaml') + try: + with open(config_path, 'w') as config_file: + config_file.write(data_yaml) + + repos = config.load_config(config_file.name) + self.assertEquals(len(repos), 1) + finally: + if os.path.exists(config_path): + os.remove(config_path)