1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-19 04:21:17 +00:00

AttributeCollection: No longer allows duplicate overriding attributes

Previously if parameters with the same names and override set to True
were added to an extension at the same level one would silently
override the other.

This is no longer the case and an error will be show instead.

Also added tests to check that this is handeled correctly
This commit is contained in:
Sebastian Goscik 2016-02-03 14:59:49 +00:00
parent 14a1bc8a5d
commit 7ad8b8522b
2 changed files with 12 additions and 2 deletions

View File

@ -82,7 +82,12 @@ class AttributeCollection(object):
return p
def __iadd__(self, other):
other = [self._to_attrcls(p) for p in other]
names = []
for p in other:
if p.name in names:
raise ValueError("Duplicate '{}' {}".format(p.name, p.__class__.__name__.split('.')[-1]))
names.append(p.name)
self.add(p)
return self
@ -687,4 +692,3 @@ class Module(Extension):
def initialize(self, context):
pass

View File

@ -320,6 +320,13 @@ class ParametersTest(TestCase):
myext = _instantiate(MyOtherExtension, mandatory=1, optional='invalid')
myext.validate()
@raises(ValueError)
def test_duplicate_param_override(self):
class DuplicateParamExtension(MyBaseExtension): # pylint: disable=W0612
parameters = [
Parameter('food', override=True, default='cheese'),
Parameter('food', override=True, default='cheese'),
]
class ModuleTest(TestCase):
@ -340,4 +347,3 @@ class ModuleTest(TestCase):
def _instantiate(cls, *args, **kwargs):
# Needed to get around Extension's __init__ checks
return cls(*args, **kwargs)