написан buildConfigProvider – в его задачи входит выдать ссылки на конфигурации которые необходимо собрать
This commit is contained in:
parent
88647c5d52
commit
b348b35b40
|
|
@ -0,0 +1 @@
|
|||
__author__ = 'rzaitov'
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
import unittest
|
||||
from utils.configs.BuildConfigProvider import BuildConfigProvider
|
||||
|
||||
|
||||
class TestBuildConfigProvider(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.provider = BuildConfigProvider()
|
||||
|
||||
def test_getAncestorsFor(self):
|
||||
wr0 = {'parent': None}
|
||||
wr1 = {'parent': wr0}
|
||||
wr2 = {'parent': wr1}
|
||||
|
||||
ancestors = self.provider.getAncestorsFor(wr2)
|
||||
|
||||
self.assertEqual(wr0, ancestors[0])
|
||||
self.assertEqual(wr1, ancestors[1])
|
||||
self.assertEqual(wr2, ancestors[2])
|
||||
|
||||
def test_unionConfig(self):
|
||||
wr0 = {
|
||||
'parent': None,
|
||||
'dict': {
|
||||
'key1': 'a',
|
||||
'key2': 'b',
|
||||
'key3': 'c',
|
||||
'key4': 'd'
|
||||
}
|
||||
}
|
||||
wr1 = {
|
||||
'parent': wr0,
|
||||
'dict':{
|
||||
'key2': 'bb',
|
||||
'key3': 'cc',
|
||||
'key4': 'dd',
|
||||
|
||||
'key5': 'ee'
|
||||
}
|
||||
}
|
||||
wr2 = {
|
||||
'parent': wr1,
|
||||
'dict':{
|
||||
'key3': 'ccc',
|
||||
'key4': 'ddd',
|
||||
|
||||
'key6': 'fff'
|
||||
}
|
||||
}
|
||||
|
||||
config = self.provider.fetchConfigFromLeafWrapper(wr2)
|
||||
expected = {
|
||||
'key1': 'a',
|
||||
'key2': 'bb',
|
||||
'key3': 'ccc',
|
||||
'key4': 'ddd',
|
||||
'key5': 'ee',
|
||||
'key6': 'fff'
|
||||
}
|
||||
self.assertDictEqual(expected, config)
|
||||
|
|
@ -1,16 +1,48 @@
|
|||
class BuildConfigProvider:
|
||||
def getBuildReadyConfigs(self, settingsDict, buildReadyList):
|
||||
assert settingsDict is not None
|
||||
assert buildReadyList is not None
|
||||
def getConfigs(self, rootConfig):
|
||||
leafs = []
|
||||
self.traverseDict(None, rootConfig, leafs)
|
||||
|
||||
for key in settingsDict:
|
||||
value = settingsDict[key]
|
||||
configs = []
|
||||
for l in leafs:
|
||||
config = self.fetchConfigFromLeafWrapper(l)
|
||||
configs.append(config)
|
||||
|
||||
return configs
|
||||
|
||||
def traverseDict(self, parent, dictForTraverse, leafs):
|
||||
wrapper = {
|
||||
'parent' : parent,
|
||||
'dict' : dictForTraverse
|
||||
}
|
||||
|
||||
isLeaf = True
|
||||
for key in dictForTraverse:
|
||||
value = dictForTraverse[key]
|
||||
|
||||
if type(value) is dict:
|
||||
self.getBuildReadyConfigs(value, buildReadyList)
|
||||
isLeaf = False
|
||||
self.traverseDict(wrapper, value, leafs)
|
||||
|
||||
elif key == 'build_ready' and value == 'true':
|
||||
buildReadyList.append(settingsDict)
|
||||
break
|
||||
if isLeaf:
|
||||
leafs.append(wrapper)
|
||||
|
||||
def fetchConfigFromLeafWrapper(self, leafWrapper):
|
||||
ancestors = self.getAncestorsFor(leafWrapper)
|
||||
|
||||
unionConf = {}
|
||||
for a in ancestors:
|
||||
unionConf.update(a['dict'])
|
||||
|
||||
return unionConf
|
||||
|
||||
def getAncestorsFor(self, leaf):
|
||||
ancestors = [leaf]
|
||||
parent = leaf['parent']
|
||||
|
||||
while parent is not None:
|
||||
ancestors.append(parent)
|
||||
parent = parent['parent']
|
||||
|
||||
ancestors.reverse()
|
||||
return ancestors
|
||||
Loading…
Reference in New Issue