提交 02db6577 编写于 作者: C Cleber Rosa 提交者: clebergnu

Merge pull request #213 from clebergnu/ruda_multiplex_updates

Ruda's multiplex updates
......@@ -51,10 +51,11 @@ class TreeNode(object):
self.children = children
def __repr__(self):
return 'TreeNode(name=%r, value=%r, parent=%r, children=%r)' % (self.name, self.value, self.parent, self.children)
return 'TreeNode(name=%r)' % self.name
def __str__(self):
return '%s=%r' % (self.name, self.environment)
variables = ['%s=%s' % (k, v) for k, v in self.environment.items()]
return '%s: %s' % (self.path, ', '.join(variables))
def __len__(self):
return len(self.get_leaves())
......
......@@ -415,6 +415,9 @@ class Job(object):
if urls is not None:
for url in urls:
params_list.append({'id': url})
else:
e_msg = "Empty test ID. A test path or alias must be provided"
raise exceptions.OptionValidationError(e_msg)
if multiplex_file is None:
if self.args and self.args.multiplex_file is not None:
......@@ -438,12 +441,9 @@ class Job(object):
params_list.append(var.environment)
else:
params_list.append({'id': url})
else:
e_msg = "Empty test ID. A test path or alias must be provided"
raise exceptions.OptionValidationError(e_msg)
if not params_list:
e_msg = "Empty test ID. A test path or alias must be provided"
e_msg = "Test(s) with empty parameter list or the number of variants is zero"
raise exceptions.OptionValidationError(e_msg)
if self.args is not None:
......
......@@ -24,16 +24,30 @@ import collections
from avocado.core import tree
def path_parent(element):
e = element.rpartition('/')[0]
if e == '':
return '/'
return e
def any_sibling(*args):
result = set(arg.parent for arg in args)
return len(args) != len(result)
def path_parent(path):
"""
From a given path, return its parent path.
:param path: the node path as string.
:return: the parent path as string.
"""
parent = path.rpartition('/')[0]
if parent == '':
return '/root'
return parent
def any_sibling(*nodes):
"""
Check if there is any sibling.
:param nodes: the nodes to check.
:return: `True` if there is any sibling or `False`.
"""
if len(nodes) < 2:
return False
parents = set(node.parent for node in nodes)
return len(nodes) != len(parents)
# only allow items which match the filter
# siblings and their children will be removed
......@@ -41,6 +55,11 @@ def any_sibling(*args):
def filter_only(keys, items):
if isinstance(keys, str):
keys = [keys]
if isinstance(items, str):
items = [items]
# the default rule is to accept
ret = True
......@@ -67,6 +86,11 @@ def filter_only(keys, items):
def filter_out(keys, items):
if isinstance(keys, str):
keys = [keys]
if isinstance(items, str):
items = [items]
for key in keys:
# ignore empty filters
if key == '':
......@@ -107,7 +131,6 @@ def multiplex(*args, **kwargs):
# second level of filtering above should use the filter strings
# extracted from the node being worked on
# (not implemented here, so using [] as placeholders)
result = [x + [y] for x in result for y in pool
if any_sibling(*(x + [y])) is False and
filter_only(y.environment.get('filter-only', []), x + [y]) and
......
......@@ -25,6 +25,65 @@ f_only = []
f_out = []
class TestPathParent(unittest.TestCase):
def test_empty_string(self):
self.assertEqual(path_parent(''), '/root')
def test_on_root(self):
self.assertEqual(path_parent('/root'), '/root')
def test_direct_parent(self):
self.assertEqual(path_parent('/root/os/linux'), '/root/os')
def test_false_direct_parent(self):
self.assertNotEqual(path_parent('/root/os/linux'), '/root')
class TestAnySibling(unittest.TestCase):
def setUp(self):
"""
Setup the following tree node structure:
os:
linux:
mint:
fedora:
win:
winxp:
win7:
win8:
"""
t = TreeNode('/root')
os = t.add_child(TreeNode('os'))
linux = os.add_child(TreeNode('linux'))
self.mint = linux.add_child(TreeNode('mint'))
self.fedora = linux.add_child(TreeNode('mint'))
win = os.add_child(TreeNode('win'))
self.winxp = win.add_child(TreeNode('winxp'))
self.win7 = win.add_child(TreeNode('win7'))
self.win8 = win.add_child(TreeNode('win8'))
def test_empty(self):
self.assertFalse(any_sibling())
def test_one_node(self):
t = TreeNode()
n = t.add_child(TreeNode('alone'))
self.assertFalse(any_sibling(n))
def test_same_parent(self):
self.assertTrue(any_sibling(self.mint, self.fedora))
self.assertTrue(any_sibling(self.winxp, self.win7, self.win8))
def test_one_linux_one_windows(self):
self.assertFalse(any_sibling(self.mint, self.winxp))
def test_two_linux_one_windows(self):
self.assertTrue(any_sibling(self.mint, self.fedora, self.winxp))
class TestMultiplex(unittest.TestCase):
def setUp(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册