Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
989ca0b2
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
989ca0b2
编写于
9月 24, 2018
作者:
C
Caio Carrara
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'clebergnu/yaml_to_mux_unwind_v2'
Signed-off-by:
N
Caio Carrara
<
ccarrara@redhat.com
>
上级
f35378a8
25de870a
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
161 addition
and
69 deletion
+161
-69
optional_plugins/varianter_yaml_to_mux/avocado_varianter_yaml_to_mux/__init__.py
...ter_yaml_to_mux/avocado_varianter_yaml_to_mux/__init__.py
+108
-69
optional_plugins/varianter_yaml_to_mux/tests/.data/mux-selftest-using.yaml
...varianter_yaml_to_mux/tests/.data/mux-selftest-using.yaml
+3
-0
optional_plugins/varianter_yaml_to_mux/tests/test_multiplex.py
...nal_plugins/varianter_yaml_to_mux/tests/test_multiplex.py
+7
-0
optional_plugins/varianter_yaml_to_mux/tests/test_mux.py
optional_plugins/varianter_yaml_to_mux/tests/test_mux.py
+43
-0
未找到文件。
optional_plugins/varianter_yaml_to_mux/avocado_varianter_yaml_to_mux/__init__.py
浏览文件 @
989ca0b2
...
...
@@ -73,20 +73,34 @@ class ListOfNodeObjects(list): # Few methods pylint: disable=R0903
"""
def
_create_from_yaml
(
path
,
cls_node
=
mux
.
MuxTreeNode
):
"""Create tree structure from yaml stream"""
def
tree_node_from_values
(
name
,
values
):
"""Create `name` node and add values"""
def
handle_control_tag
(
node
,
value
):
"""Handling of YAML tags (except of !using)"""
def
normalize_path
(
path
):
"""End the path with single '/', None when empty path"""
def
_normalize_path
(
path
):
"""
End the path with single '/'
:param path: original path
:type path: str
:returns: path with trailing '/', or None when empty path
:rtype: str or None
"""
if
not
path
:
return
if
path
[
-
1
]
!=
'/'
:
path
+=
'/'
return
path
def
_handle_control_tag
(
path
,
cls_node
,
node
,
value
):
"""
Handling of most YAML control tags (all but "!using")
:param path: path on the YAML
:type path: str
:param cls_node: the class of the node
:type cls_node: :class:`avocado.core.tree.TreeNode` or similar
:param node: the node in which to handle control tags
:type node: instance of :class:`avocado.core.tree.TreeNode` or similar
:param value: the value of the node
"""
if
value
[
0
].
code
==
YAML_INCLUDE
:
# Include file
ypath
=
value
[
1
]
...
...
@@ -96,25 +110,33 @@ def _create_from_yaml(path, cls_node=mux.MuxTreeNode):
raise
ValueError
(
"File '%s' included from '%s' does not "
"exist."
%
(
ypath
,
path
))
node
.
merge
(
_create_from_yaml
(
'/:'
+
ypath
,
cls_node
))
elif
value
[
0
].
code
==
YAML_REMOVE_NODE
:
elif
value
[
0
].
code
in
(
YAML_REMOVE_NODE
,
YAML_REMOVE_VALUE
)
:
value
[
0
].
value
=
value
[
1
]
# set the name
node
.
ctrl
.
append
(
value
[
0
])
# add "blue pill" of death
elif
value
[
0
].
code
==
YAML_REMOVE_VALUE
:
value
[
0
].
value
=
value
[
1
]
# set the name
node
.
ctrl
.
append
(
value
[
0
])
elif
value
[
0
].
code
==
YAML_MUX
:
node
.
multiplex
=
True
elif
value
[
0
].
code
==
YAML_FILTER_ONLY
:
new_value
=
normalize_path
(
value
[
1
])
new_value
=
_
normalize_path
(
value
[
1
])
if
new_value
:
node
.
filters
[
0
].
append
(
new_value
)
elif
value
[
0
].
code
==
YAML_FILTER_OUT
:
new_value
=
normalize_path
(
value
[
1
])
new_value
=
_
normalize_path
(
value
[
1
])
if
new_value
:
node
.
filters
[
1
].
append
(
new_value
)
def
handle_control_tag_using
(
name
,
using
,
value
):
"""Handling of the !using tag"""
def
_handle_control_tag_using
(
path
,
name
,
using
,
value
):
"""
Handling of the "!using" YAML control tag
:param path: path on the YAML
:type path: str
:param name: name to be applied in the "!using" tag
:type name: str
:param using: wether using is already being used
:type using: bool
:param value: the value of the node
"""
if
using
:
raise
ValueError
(
"!using can be used only once per "
"node! (%s:%s)"
%
(
path
,
name
))
...
...
@@ -125,6 +147,39 @@ def _create_from_yaml(path, cls_node=mux.MuxTreeNode):
using
=
using
[:
-
1
]
return
using
def
_apply_using
(
name
,
cls_node
,
using
,
node
):
"""
Create the structure defined by "!using" and return the new root
:param name: the tag name to have the "!using" applied to
:type name: str
:param cls_node: the class of the node
:type cls_node: :class:`avocado.core.tree.TreeNode` or similar
:param using: the new location to put the tag into
:type using: bool
:param node: the node in which to handle control tags
:type node: instance of :class:`avocado.core.tree.TreeNode` or similar
"""
if
name
is
not
''
:
for
name
in
using
.
split
(
'/'
)[::
-
1
]:
node
=
cls_node
(
name
,
children
=
[
node
])
else
:
using
=
using
.
split
(
'/'
)[::
-
1
]
node
.
name
=
using
.
pop
()
while
True
:
if
not
using
:
break
name
=
using
.
pop
()
# 'using' is list pylint: disable=E1101
node
=
cls_node
(
name
,
children
=
[
node
])
node
=
cls_node
(
''
,
children
=
[
node
])
return
node
def
_create_from_yaml
(
path
,
cls_node
=
mux
.
MuxTreeNode
):
"""Create tree structure from yaml stream"""
def
tree_node_from_values
(
name
,
values
):
"""Create `name` node and add values"""
def
node_content_from_node
(
node
,
values
,
using
):
"""Processes node values into the current node content"""
for
value
in
values
:
...
...
@@ -132,9 +187,9 @@ def _create_from_yaml(path, cls_node=mux.MuxTreeNode):
node
.
add_child
(
value
)
elif
isinstance
(
value
[
0
],
mux
.
Control
):
if
value
[
0
].
code
==
YAML_USING
:
using
=
handle_control_tag_using
(
name
,
using
,
value
[
1
])
using
=
_handle_control_tag_using
(
path
,
name
,
using
,
value
[
1
])
else
:
handle_control_tag
(
node
,
value
)
_handle_control_tag
(
path
,
cls_node
,
node
,
value
)
elif
isinstance
(
value
[
1
],
collections
.
OrderedDict
):
node
.
add_child
(
tree_node_from_values
(
str
(
value
[
0
]),
value
[
1
]))
...
...
@@ -147,9 +202,9 @@ def _create_from_yaml(path, cls_node=mux.MuxTreeNode):
for
key
,
value
in
iteritems
(
values
):
if
isinstance
(
key
,
mux
.
Control
):
if
key
.
code
==
YAML_USING
:
using
=
handle_control_tag_using
(
name
,
using
,
value
)
using
=
_handle_control_tag_using
(
path
,
name
,
using
,
value
)
else
:
handle_control_tag
(
node
,
[
key
,
value
])
_handle_control_tag
(
path
,
cls_node
,
node
,
[
key
,
value
])
elif
(
isinstance
(
value
,
collections
.
OrderedDict
)
or
value
is
None
):
node
.
add_child
(
tree_node_from_values
(
key
,
value
))
...
...
@@ -157,22 +212,6 @@ def _create_from_yaml(path, cls_node=mux.MuxTreeNode):
node
.
value
[
key
]
=
value
return
using
def
apply_using
(
name
,
using
,
node
):
'''Create the structure defined by using and return the new root'''
if
name
is
not
''
:
for
name
in
using
.
split
(
'/'
)[::
-
1
]:
node
=
cls_node
(
name
,
children
=
[
node
])
else
:
using
=
using
.
split
(
'/'
)[::
-
1
]
node
.
name
=
using
.
pop
()
while
True
:
if
not
using
:
break
name
=
using
.
pop
()
# 'using' is list pylint: disable=E1101
node
=
cls_node
(
name
,
children
=
[
node
])
node
=
cls_node
(
''
,
children
=
[
node
])
return
node
# Initialize the node
node
=
cls_node
(
str
(
name
))
if
not
values
:
...
...
@@ -187,7 +226,7 @@ def _create_from_yaml(path, cls_node=mux.MuxTreeNode):
# Prefix nodes if tag "!using" was used
if
using
:
node
=
apply_using
(
nam
e
,
using
,
node
)
node
=
_apply_using
(
name
,
cls_nod
e
,
using
,
node
)
return
node
def
mapping_to_tree_loader
(
loader
,
node
,
looks_like_node
=
False
):
...
...
optional_plugins/varianter_yaml_to_mux/tests/.data/mux-selftest-using.yaml
0 → 100644
浏览文件 @
989ca0b2
!using
:
/foo
bar
:
!using
:
baz
optional_plugins/varianter_yaml_to_mux/tests/test_multiplex.py
浏览文件 @
989ca0b2
...
...
@@ -55,6 +55,13 @@ class MultiplexTests(unittest.TestCase):
result
=
self
.
run_and_check
(
cmd_line
,
expected_rc
)
self
.
assertIn
(
'No such file or directory'
,
result
.
stderr_text
)
def
test_mplex_plugin_using
(
self
):
cmd_line
=
(
'%s variants -m /:optional_plugins/varianter_yaml_to_mux/'
'tests/.data/mux-selftest-using.yaml'
%
AVOCADO
)
expected_rc
=
exit_codes
.
AVOCADO_ALL_OK
result
=
self
.
run_and_check
(
cmd_line
,
expected_rc
)
self
.
assertIn
(
b
' /foo/baz/bar'
,
result
.
stdout
)
@
unittest
.
skipIf
(
sys
.
version_info
[
0
]
==
3
,
"Test currently broken on Python 3"
)
def
test_mplex_debug
(
self
):
...
...
optional_plugins/varianter_yaml_to_mux/tests/test_mux.py
浏览文件 @
989ca0b2
...
...
@@ -535,6 +535,49 @@ class TestPathParent(unittest.TestCase):
self
.
assertNotEqual
(
mux
.
path_parent
(
'/os/linux'
),
'/'
)
class
TestCreateFromYaml
(
unittest
.
TestCase
):
def
test_normalize_path
(
self
):
self
.
assertEqual
(
yaml_to_mux
.
_normalize_path
(
''
),
None
)
self
.
assertEqual
(
yaml_to_mux
.
_normalize_path
(
'path'
),
'path/'
)
def
test_handle_control_path_include_file_does_not_exist
(
self
):
with
self
.
assertRaises
(
ValueError
):
yaml_to_mux
.
_handle_control_tag
(
'original_fake_file.yaml'
,
mux
.
MuxTreeNode
,
mux
.
MuxTreeNode
(),
(
mux
.
Control
(
yaml_to_mux
.
YAML_INCLUDE
),
'unexisting_include.yaml'
))
def
test_handle_control_path_remove
(
self
):
klass
=
mux
.
MuxTreeNode
node
=
klass
()
control
=
mux
.
Control
(
yaml_to_mux
.
YAML_REMOVE_NODE
)
to_be_removed
=
'node_to_be_removed'
yaml_to_mux
.
_handle_control_tag
(
'fake_path'
,
klass
,
node
,
(
control
,
to_be_removed
))
self
.
assertEqual
(
control
.
value
,
to_be_removed
)
self
.
assertIn
(
control
,
node
.
ctrl
)
def
test_handle_control_tag_using_multiple
(
self
):
with
self
.
assertRaises
(
ValueError
):
yaml_to_mux
.
_handle_control_tag_using
(
'original_fake_file.yaml'
,
'name'
,
True
,
'using'
)
def
test_handle_control_tag_using
(
self
):
using
=
yaml_to_mux
.
_handle_control_tag_using
(
'fake_path'
,
'name'
,
False
,
'/using/path/'
)
self
.
assertEqual
(
using
,
'using/path'
)
def
test_apply_using
(
self
):
node
=
yaml_to_mux
.
_apply_using
(
'bar'
,
mux
.
MuxTreeNode
,
'foo'
,
mux
.
MuxTreeNode
())
self
.
assertEqual
(
node
.
path
,
'/foo'
)
class
TestFingerprint
(
unittest
.
TestCase
):
def
test_fingerprint
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录