Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions git_aggregator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)