提交 7d4b8e08 编写于 作者: L Lukáš Doktor

core.parameters: Consider same-path origin as the same origin

Currently we compare the full TreeNodeEnvironment object to make sure
they come from the same origin, which only works for connected tree. But
Avocado supports (and uses in json-load) passing leaves of unconnected
trees, but then the TreeNodeEnvironments are not matching.

Let's rely only on "TreeNodeEnvironment.path" and declare these matching
environments, no matter what values are stored (see selftest for
details)
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 c606cd79
......@@ -250,7 +250,8 @@ class AvocadoParam(object):
if not ret:
raise NoMatchError("No matches to %s => %s in %s"
% (path.pattern, key, self.str_leaves_variant))
if len(set([_[1] for _ in ret])) == 1: # single source of results
# make sure all params come from the same origin
if len(set([_[1].path for _ in ret])) == 1:
return ret[0][0]
else:
raise ValueError("Multiple %s leaves contain the key '%s'; %s"
......
......@@ -21,3 +21,35 @@ class Parameters(unittest.TestCase):
'foo/')
self.assertEqual(params._greedy_path_to_re('/foo/*').pattern,
'/foo/')
def test_same_origin_of_different_nodes(self):
# ideally we have one tree, therefor shared key
# have identical origin (id of the origin env)
foo = tree.TreeNode().get_node("/foo", True)
root = foo.parent
root.value = {'timeout': 1}
bar = root.get_node("/bar", True)
params1 = parameters.AvocadoParams([foo, bar], '/')
self.assertEqual(params1.get('timeout'), 1)
self.assertEqual(params1.get('timeout', '/foo/'), 1)
self.assertEqual(params1.get('timeout', '/bar/'), 1)
# Sometimes we get multiple trees, but if they claim the origin
# is of the same path, let's trust it (even when the values
# differ)
# note: This is an artificial example which should not happen
# in production. Anyway in json-variants-loader we do create
# only leave-nodes without connecting the parents, which result
# in same paths with different node objects. Let's make sure
# they behave correctly.
baz = tree.TreeNode().get_node("/baz", True)
baz.parent.value = {'timeout': 2}
params2 = parameters.AvocadoParams([foo, baz], '/')
self.assertEqual(params2.get('timeout'), 1)
self.assertEqual(params2.get('timeout', '/foo/'), 1)
self.assertEqual(params2.get('timeout', '/baz/'), 2)
# Note: Different origin of the same value, which should produce
# a crash, are tested in yaml2mux selftest
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册