未验证 提交 f35378a8 编写于 作者: C Caio Carrara

Merge remote-tracking branch 'clebergnu/revert_yaml_to_mux_py3'

Signed-off-by: NCaio Carrara <ccarrara@redhat.com>
......@@ -31,7 +31,6 @@ from six import iteritems
from avocado.core import exit_codes
from avocado.core.output import LOG_UI
from avocado.core.plugin_interfaces import CLI, Varianter
from avocado.utils import astring
from . import mux
......@@ -137,9 +136,8 @@ def _create_from_yaml(path, cls_node=mux.MuxTreeNode):
else:
handle_control_tag(node, value)
elif isinstance(value[1], collections.OrderedDict):
child = tree_node_from_values(astring.to_text(value[0]),
value[1])
node.add_child(child)
node.add_child(tree_node_from_values(str(value[0]),
value[1]))
else:
node.value[value[0]] = value[1]
return using
......@@ -176,7 +174,7 @@ def _create_from_yaml(path, cls_node=mux.MuxTreeNode):
return node
# Initialize the node
node = cls_node(astring.to_text(name))
node = cls_node(str(name))
if not values:
return node
using = ''
......@@ -220,7 +218,7 @@ def _create_from_yaml(path, cls_node=mux.MuxTreeNode):
if isinstance(values, ListOfNodeObjects): # New node from list
objects.append(tree_node_from_values(name, values))
elif values is None: # Empty node
objects.append(cls_node(astring.to_text(name)))
objects.append(cls_node(str(name)))
else: # Values
objects.append((name, values))
return objects
......@@ -321,11 +319,10 @@ def create_from_yaml(paths, debug=False):
merge(data, path)
# Yaml can raise IndexError on some files
except (yaml.YAMLError, IndexError) as details:
if (u'mapping values are not allowed in this context' in
astring.to_text(details)):
details = (u"%s\nMake sure !tags and colons are separated by a "
u"space (eg. !include :)" % details)
msg = u"Invalid multiplex file '%s': %s" % (path, details)
if 'mapping values are not allowed in this context' in str(details):
details = ("%s\nMake sure !tags and colons are separated by a "
"space (eg. !include :)" % details)
msg = "Invalid multiplex file '%s': %s" % (path, details)
raise IOError(2, msg, path)
return data
......@@ -380,7 +377,6 @@ class YamlToMux(mux.MuxPlugin, Varianter):
def initialize(self, args):
debug = getattr(args, "varianter_debug", False)
if debug:
data = mux.MuxTreeNodeDebug()
else:
......
# Put everything into /švirt
!using : švirt
# Put everything into /virt
!using : virt
# Following line makes it look exactly as mux-selftest.yaml
!include : mux-selftest.yaml
distro: !mux
# This line extends the distro branch using include
!include : mux-šelftest-distro.yaml
# remove node called "šmint"
!remove_node : šmi.*nt
# This is a new /distro/šmint appended as latest child
šmint:
!include : mux-selftest-distro.yaml
# remove node called "mint"
!remove_node : mi.*nt
# This is a new /distro/mint appended as latest child
mint:
new_mint: True
fedora:
!remove_value : init.*
......@@ -27,7 +27,7 @@ new_node:
# removed during parse time, absolute location is not supported and
# not even planned)
!using : /absolutely/fresh/
new_value: "šomething"
new_value: "something"
# Check that mapping keys are not converted to values, while values are
# while value between quotes stays as string.
on:
......@@ -39,7 +39,7 @@ on:
# should be similar.
dict:
explicit: !!python/dict
fooš: šbar
foo: bar
bar: baz
in_list:
- foo: bar
......
......@@ -55,6 +55,5 @@ env: !mux
prod:
opt_CFLAGS: '-O2'
distro: !mux
# Use utf-8 character
šmint:
mint:
init: 'systemv'
......@@ -7,11 +7,11 @@ import sys
from avocado.core import exit_codes
from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..')
basedir = os.path.abspath(basedir)
AVOCADO = os.environ.get("UNITTEST_AVOCADO_CMD",
"%s ./scripts/avocado" % sys.executable)
AVOCADO = os.environ.get("UNITTEST_AVOCADO_CMD", "./scripts/avocado")
DEBUG_OUT = b"""
Variant mint-debug-amd-virtio-a9d2: amd@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, virtio@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, mint@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, debug@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml
......@@ -55,6 +55,8 @@ class MultiplexTests(unittest.TestCase):
result = self.run_and_check(cmd_line, expected_rc)
self.assertIn('No such file or directory', result.stderr_text)
@unittest.skipIf(sys.version_info[0] == 3,
"Test currently broken on Python 3")
def test_mplex_debug(self):
cmd_line = ('%s variants -c -d -m '
'/:optional_plugins/varianter_yaml_to_mux/tests/.data/mux-selftest.yaml '
......@@ -142,6 +144,8 @@ class MultiplexTests(unittest.TestCase):
"passtest.py" % (AVOCADO, self.tmpdir))
self.run_and_check(cmd_line, exit_codes.AVOCADO_ALL_OK, (1, 0))
@unittest.skipIf(sys.version_info[0] == 3,
"Test currently broken on Python 3")
def test_run_mplex_params(self):
for variant_msg in (('/run/short', 'A'),
('/run/medium', 'ASDFASDF'),
......
......@@ -5,14 +5,11 @@ import pickle
import sys
import unittest
from six import PY2
import yaml
import avocado_varianter_yaml_to_mux as yaml_to_mux
from avocado_varianter_yaml_to_mux import mux
from avocado.core import tree, parameters
from avocado.utils import astring
BASEDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
BASEDIR = os.path.abspath(BASEDIR)
......@@ -81,15 +78,10 @@ class TestMuxTree(unittest.TestCase):
def test_basic_functions(self):
# repr
if PY2:
self.assertEqual("MuxTreeNode(name=u'hw')",
repr(self.tree.children[0]))
else:
self.assertEqual("MuxTreeNode(name='hw')",
repr(self.tree.children[0]))
self.assertEqual("MuxTreeNode(name='hw')", repr(self.tree.children[0]))
# str
self.assertEqual(u"/distro/\u0161mint: init=systemv",
astring.to_text(self.tree.children[1].children[1]))
self.assertEqual("/distro/mint: init=systemv",
str(self.tree.children[1].children[1]))
# len
self.assertEqual(8, len(self.tree)) # number of leaves
# __iter__
......@@ -131,28 +123,23 @@ class TestMuxTree(unittest.TestCase):
vals = {'opt_CFLAGS': '-Os'}
self.assertEqual(vals, self.tree.children[2].environment)
# leaves order
leaves = ['intel', 'amd', 'arm', 'scsi', 'virtio', 'fedora',
u'\u0161mint', 'prod']
leaves = ['intel', 'amd', 'arm', 'scsi', 'virtio', 'fedora', 'mint',
'prod']
self.assertEqual(leaves, self.tree.get_leaves())
tree_view = tree.tree_view(self.tree, 0, False)
# ascii treeview contains only ascii chars
tree_view.decode('ascii')
# ascii treeview contain all leaves
# ascii contain all leaves and doesn't raise any exceptions
tree_view = tree.tree_view(self.tree, 0, False).decode('ascii')
for leaf in leaves:
# In ascii mode we replace non-ascii character using
# xmlcharrefreplace, make sure this is performed
leaf = leaf.encode('ascii', errors='xmlcharrefreplace')
self.assertIn(leaf, tree_view, "Leaf %s not in ascii:\n%s"
% (leaf, tree_view))
def test_filters(self):
tree2 = copy.deepcopy(self.tree)
exp = ['intel', 'amd', 'arm', 'fedora', u'\u0161mint', 'prod']
exp = ['intel', 'amd', 'arm', 'fedora', 'mint', 'prod']
act = mux.apply_filters(tree2,
filter_only=['/hw/cpu', '']).get_leaves()
self.assertEqual(exp, act)
tree2 = copy.deepcopy(self.tree)
exp = ['scsi', 'virtio', 'fedora', u'\u0161mint', 'prod']
exp = ['scsi', 'virtio', 'fedora', 'mint', 'prod']
act = mux.apply_filters(tree2,
filter_out=['/hw/cpu', '']).get_leaves()
self.assertEqual(exp, act)
......@@ -167,7 +154,7 @@ class TestMuxTree(unittest.TestCase):
tree3.children[0].add_child(mux.MuxTreeNode('cpu', {'test_value': ['z']}))
tree2.merge(tree3)
exp = ['intel', 'amd', 'arm', 'scsi', 'virtio', 'default', 'virtio',
'fedora', u'\u0161mint', 'prod']
'fedora', 'mint', 'prod']
self.assertEqual(exp, tree2.get_leaves())
self.assertEqual({'corruptlist': ['upper_node_list'],
'another_value': 'bbb'},
......@@ -184,24 +171,24 @@ class TestMuxTree(unittest.TestCase):
tree2_yaml_url = '/:%s' % tree2_yaml_path
tree2 = yaml_to_mux.create_from_yaml([tree2_yaml_url])
exp = ['intel', 'amd', 'arm', 'scsi', 'virtio', 'fedora', '6',
'7', 'gentoo', u'\u0161mint', 'prod', 'new_node', 'on', 'dict']
'7', 'gentoo', 'mint', 'prod', 'new_node', 'on', 'dict']
act = tree2.get_leaves()
oldroot = tree2.children[0]
self.assertEqual(exp, act)
self.assertEqual(tree2.children[0].children[0].path, u"/\u0161virt/hw")
self.assertEqual(tree2.children[0].children[0].path, "/virt/hw")
self.assertEqual({'enterprise': True},
oldroot.children[1].children[1].value)
self.assertEqual({'new_init': 'systemd'},
oldroot.children[1].children[0].value)
self.assertEqual({'is_cool': True},
oldroot.children[1].children[2].value)
self.assertEqual({'new_value': u'\u0161omething'},
self.assertEqual({'new_value': 'something'},
oldroot.children[3].children[0].children[0].value)
# Convert values, but not keys
self.assertEqual({'on': True, "true": "true"},
oldroot.children[4].value)
# Dicts as values
self.assertEqual({"explicit": {u"foo\u0161": u"\u0161bar", "bar": "baz"},
self.assertEqual({"explicit": {"foo": "bar", "bar": "baz"},
"in_list": [{"foo": "bar", "bar": "baz"}]},
oldroot.children[5].value)
# multiplex root (always True)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册