Commit 278b28bc authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Implement merge of multiple psot repositories

parent c62b52a7
......@@ -11,7 +11,6 @@ class Repository:
def load_config(self):
'''return a dictionary with the whole configuration for this repository'''
config = self.load_config_file()
print(config)
config['profiles'] = self.load_profiles()
config['modules'] = self.load_modules()
self.normalize_profiles(config['profiles'])
......@@ -101,11 +100,12 @@ class Config:
self.repo_paths = repository_paths
def merge_config(self, source, target):
import jsonmerge
# Quick hack: replacement instead of merge
# TODO do an actual merge instead of just a replacement
for k in source:
target[k] = source[k]
return
schema = { 'properties': {'profiles':{'mergeStrategy':'append'}} }
return jsonmerge.merge(target, source, schema)
def load_config(self):
config = {}
......@@ -113,7 +113,7 @@ class Config:
for repo_path in self.repo_paths:
repo = Repository(repo_path)
repo_config = repo.load_config()
self.merge_config(repo_config, config)
config = self.merge_config(repo_config, config)
# quick hack
# use the last script directory
# TODO replace with list
......
tools:
test: bla
override: 2
name: 'example2'
info: 'example module for testing'
analysis:
script: 'run_example.sh'
parameters:
converter:
script: 'convert_example.sh'
parameters:
name: 'test2'
info: 'Profile for testing purposes'
modules:
example2:
......@@ -31,3 +31,29 @@ class TestExampleRepositoryIsLoadedCorrectly(unittest.TestCase):
def test_that_config_exists(self):
self.assertTrue('tools' in self.config, 'config.yml not loaded')
class TestMergingRepositoriesWorksCorrectly(unittest.TestCase):
def setUp(self):
repo_path1 = pkg_resources.resource_filename('tests', 'data/example_repo/')
repo_path2 = pkg_resources.resource_filename('tests', 'data/example_repo2/')
self.repository = config.Config([repo_path1, repo_path2])
self.config = self.repository.load_config()
# output config for debugging purposes
#from pprint import pformat
#print(pformat(self.config))
#print()
def test_profiles_merged(self):
profiles = self.config['profiles']
self.assertTrue(len(profiles) is 2, 'Only {} profile(s) found, expected 2'.format(str(len(profiles))))
def test_modules_merged(self):
modules = self.config['modules']
self.assertTrue(len(modules) is 2, 'Only {} module(s) found, expected 2'.format(str(len(modules))))
def test_config_value_was_overriden(self):
value = self.config['tools']['override']
self.assertEqual(value, 2)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment