Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
cc0cb287
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,发现更多精彩内容 >>
未验证
提交
cc0cb287
编写于
12月 13, 2018
作者:
C
Caio Carrara
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'clebergnu/tags_key_val_prep2'
Signed-off-by:
N
Caio Carrara
<
ccarrara@redhat.com
>
上级
02314957
00293a40
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
123 addition
and
31 deletion
+123
-31
avocado/core/loader.py
avocado/core/loader.py
+33
-12
selftests/unit/test_loader.py
selftests/unit/test_loader.py
+90
-19
未找到文件。
avocado/core/loader.py
浏览文件 @
cc0cb287
...
...
@@ -63,6 +63,33 @@ class MissingTest(object):
"""
def
parse_filter_by_tags
(
filter_by_tags
):
"""
Parses the various filter by tags in "command line" format
The filtering of tests usually happens my means of "--filter-by-tags"
command line options, and many can be given. This parses the contents
of those into a list of must/must_not pairs, which can be used directly
for comparisons when filtering.
:param filter_by_tags: params in the format given to "-t/--filter-by-tags"
:type filter_by_tags: list of str
:returns: list of tuples with (set, set)
"""
result
=
[]
for
raw_tags
in
filter_by_tags
:
required_tags
=
raw_tags
.
split
(
','
)
must
=
set
()
must_not
=
set
()
for
tag
in
required_tags
:
if
tag
.
startswith
(
'-'
):
must_not
.
add
(
tag
[
1
:])
else
:
must
.
add
(
tag
)
result
.
append
((
must
,
must_not
))
return
result
def
filter_test_tags
(
test_suite
,
filter_by_tags
,
include_empty
=
False
):
"""
Filter the existing (unfiltered) test suite based on tags
...
...
@@ -80,22 +107,16 @@ def filter_test_tags(test_suite, filter_by_tags, include_empty=False):
:type include_empty: bool
"""
filtered
=
[]
must_must_nots
=
parse_filter_by_tags
(
filter_by_tags
)
for
klass
,
info
in
test_suite
:
test_tags
=
info
.
get
(
'tags'
,
{})
if
not
test_tags
and
include_empty
:
filtered
.
append
((
klass
,
info
))
if
not
test_tags
:
if
include_empty
:
filtered
.
append
((
klass
,
info
))
continue
for
raw_tags
in
filter_by_tags
:
required_tags
=
raw_tags
.
split
(
','
)
must
=
set
()
must_not
=
set
()
for
tag
in
required_tags
:
if
tag
.
startswith
(
'-'
):
must_not
.
add
(
tag
[
1
:])
else
:
must
.
add
(
tag
)
for
must
,
must_not
in
must_must_nots
:
if
must_not
.
intersection
(
test_tags
):
continue
...
...
selftests/unit/test_loader.py
浏览文件 @
cc0cb287
...
...
@@ -100,6 +100,10 @@ class SafeX86Test(Test):
def test_safe_x86(self):
pass
class NoTagsTest(Test):
def test_no_tags(self):
pass
if __name__ == "__main__":
main()
"""
...
...
@@ -444,7 +448,7 @@ class TagFilter(unittest.TestCase):
loader
.
DiscoverMode
.
ALL
)
def
test_no_tag_filter
(
self
):
self
.
assertEqual
(
len
(
self
.
test_suite
),
6
)
self
.
assertEqual
(
len
(
self
.
test_suite
),
7
)
self
.
assertEqual
(
self
.
test_suite
[
0
][
0
],
'FastTest'
)
self
.
assertEqual
(
self
.
test_suite
[
0
][
1
][
'methodName'
],
'test_fast'
)
self
.
assertEqual
(
self
.
test_suite
[
1
][
0
],
'FastTest'
)
...
...
@@ -455,19 +459,48 @@ class TagFilter(unittest.TestCase):
self
.
assertEqual
(
self
.
test_suite
[
3
][
1
][
'methodName'
],
'test_slow_unsafe'
)
self
.
assertEqual
(
self
.
test_suite
[
4
][
0
],
'SafeTest'
)
self
.
assertEqual
(
self
.
test_suite
[
4
][
1
][
'methodName'
],
'test_safe'
)
self
.
assertEqual
(
self
.
test_suite
[
5
][
0
],
'SafeX86Test'
)
self
.
assertEqual
(
self
.
test_suite
[
5
][
1
][
'methodName'
],
'test_safe_x86'
)
self
.
assertEqual
(
self
.
test_suite
[
6
][
0
],
'NoTagsTest'
)
self
.
assertEqual
(
self
.
test_suite
[
6
][
1
][
'methodName'
],
'test_no_tags'
)
def
test_filter_fast_net
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'fast,net'
])
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'fast,net'
]
,
False
)
self
.
assertEqual
(
len
(
filtered
),
2
)
self
.
assertEqual
(
filtered
[
0
][
0
],
'FastTest'
)
self
.
assertEqual
(
filtered
[
0
][
1
][
'methodName'
],
'test_fast'
)
self
.
assertEqual
(
filtered
[
1
][
0
],
'FastTest'
)
self
.
assertEqual
(
filtered
[
1
][
1
][
'methodName'
],
'test_fast_other'
)
def
test_filter_fast_net_include_empty
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'fast,net'
],
True
)
self
.
assertEqual
(
len
(
filtered
),
3
)
self
.
assertEqual
(
filtered
[
0
][
0
],
'FastTest'
)
self
.
assertEqual
(
filtered
[
0
][
1
][
'methodName'
],
'test_fast'
)
self
.
assertEqual
(
filtered
[
1
][
0
],
'FastTest'
)
self
.
assertEqual
(
filtered
[
1
][
1
][
'methodName'
],
'test_fast_other'
)
self
.
assertEqual
(
filtered
[
2
][
0
],
'NoTagsTest'
)
self
.
assertEqual
(
filtered
[
2
][
1
][
'methodName'
],
'test_no_tags'
)
def
test_filter_arch
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'arch'
],
False
)
self
.
assertEqual
(
len
(
filtered
),
1
)
self
.
assertEqual
(
filtered
[
0
][
0
],
'SafeX86Test'
)
self
.
assertEqual
(
filtered
[
0
][
1
][
'methodName'
],
'test_safe_x86'
)
def
test_filter_arch_include_empty
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'arch'
],
True
)
self
.
assertEqual
(
len
(
filtered
),
2
)
self
.
assertEqual
(
filtered
[
0
][
0
],
'SafeX86Test'
)
self
.
assertEqual
(
filtered
[
0
][
1
][
'methodName'
],
'test_safe_x86'
)
self
.
assertEqual
(
filtered
[
1
][
0
],
'NoTagsTest'
)
self
.
assertEqual
(
filtered
[
1
][
1
][
'methodName'
],
'test_no_tags'
)
def
test_filter_fast_net__slow_disk_unsafe
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'fast,net'
,
'slow,disk,unsafe'
])
'slow,disk,unsafe'
],
False
)
self
.
assertEqual
(
len
(
filtered
),
3
)
self
.
assertEqual
(
filtered
[
0
][
0
],
'FastTest'
)
self
.
assertEqual
(
filtered
[
0
][
1
][
'methodName'
],
'test_fast'
)
...
...
@@ -479,7 +512,8 @@ class TagFilter(unittest.TestCase):
def
test_filter_fast_net__slow_disk
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'fast,net'
,
'slow,disk'
])
'slow,disk'
],
False
)
self
.
assertEqual
(
len
(
filtered
),
4
)
self
.
assertEqual
(
filtered
[
0
][
0
],
'FastTest'
)
self
.
assertEqual
(
filtered
[
0
][
1
][
'methodName'
],
'test_fast'
)
...
...
@@ -492,32 +526,52 @@ class TagFilter(unittest.TestCase):
def
test_filter_not_fast_not_slow
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'-fast,-slow'
])
[
'-fast,-slow'
],
False
)
self
.
assertEqual
(
len
(
filtered
),
2
)
self
.
assertEqual
(
filtered
[
0
][
0
],
'SafeTest'
)
self
.
assertEqual
(
filtered
[
0
][
1
][
'methodName'
],
'test_safe'
)
self
.
assertEqual
(
filtered
[
1
][
0
],
'SafeX86Test'
)
self
.
assertEqual
(
filtered
[
1
][
1
][
'methodName'
],
'test_safe_x86'
)
def
test_filter_not_fast_not_slow_include_empty
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'-fast,-slow'
],
True
)
self
.
assertEqual
(
len
(
filtered
),
3
)
self
.
assertEqual
(
filtered
[
0
][
0
],
'SafeTest'
)
self
.
assertEqual
(
filtered
[
0
][
1
][
'methodName'
],
'test_safe'
)
self
.
assertEqual
(
filtered
[
1
][
0
],
'SafeX86Test'
)
self
.
assertEqual
(
filtered
[
1
][
1
][
'methodName'
],
'test_safe_x86'
)
self
.
assertEqual
(
filtered
[
2
][
0
],
'NoTagsTest'
)
self
.
assertEqual
(
filtered
[
2
][
1
][
'methodName'
],
'test_no_tags'
)
def
test_filter_not_fast_not_slow_not_safe
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'-fast,-slow,-safe'
])
[
'-fast,-slow,-safe'
],
False
)
self
.
assertEqual
(
len
(
filtered
),
0
)
def
test_filter_not_fast_not_slow_not_safe_others_dont_exist
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'-fast,-slow,-safe'
,
'does,not,exist'
])
'does,not,exist'
],
False
)
self
.
assertEqual
(
len
(
filtered
),
0
)
def
test_load_tags
(
self
):
tags_map
=
{
'FastTest.test_fast'
:
{
'fast'
:
None
,
'net'
:
None
},
'FastTest.test_fast_other'
:
{
'fast'
:
None
,
'net'
:
None
},
'SlowTest.test_slow'
:
{
'slow'
:
None
,
'disk'
:
None
},
'SlowUnsafeTest.test_slow_unsafe'
:
{
'slow'
:
None
,
'disk'
:
None
,
'unsafe'
:
None
},
'SafeTest.test_safe'
:
{
'safe'
:
None
},
'SafeX86Test.test_safe_x86'
:
{
'safe'
:
None
,
'arch'
:
set
([
'x86_64'
])}}
tags_map
=
{
'FastTest.test_fast'
:
{
'fast'
:
None
,
'net'
:
None
},
'FastTest.test_fast_other'
:
{
'fast'
:
None
,
'net'
:
None
},
'SlowTest.test_slow'
:
{
'slow'
:
None
,
'disk'
:
None
},
'SlowUnsafeTest.test_slow_unsafe'
:
{
'slow'
:
None
,
'disk'
:
None
,
'unsafe'
:
None
},
'SafeTest.test_safe'
:
{
'safe'
:
None
},
'SafeX86Test.test_safe_x86'
:
{
'safe'
:
None
,
'arch'
:
set
([
'x86_64'
])},
'NoTagsTest.test_no_tags'
:
{}
}
for
_
,
info
in
self
.
test_suite
:
name
=
info
[
'name'
].
split
(
':'
,
1
)[
1
]
...
...
@@ -536,9 +590,26 @@ class TagFilter2(unittest.TestCase):
this_loader
=
loader
.
FileLoader
(
None
,
{})
test_suite
=
this_loader
.
discover
(
test_script
.
path
,
loader
.
DiscoverMode
.
ALL
)
self
.
assertEqual
([],
loader
.
filter_test_tags
(
test_suite
,
[]))
self
.
assertEqual
(
test_suite
,
loader
.
filter_test_tags
(
test_suite
,
[],
True
))
self
.
assertEqual
([],
loader
.
filter_test_tags
(
test_suite
,
[],
False
))
self
.
assertEqual
(
test_suite
,
loader
.
filter_test_tags
(
test_suite
,
[],
True
))
class
ParseFilterByTags
(
unittest
.
TestCase
):
def
test_must
(
self
):
self
.
assertEqual
(
loader
.
parse_filter_by_tags
([
'foo,bar,baz'
]),
[(
set
([
'foo'
,
'bar'
,
'baz'
]),
set
([]))])
def
test_must_must_not
(
self
):
self
.
assertEqual
(
loader
.
parse_filter_by_tags
([
'foo,-bar,baz'
]),
[(
set
([
'foo'
,
'baz'
]),
set
([
'bar'
]))])
def
test_musts_must_nots
(
self
):
self
.
assertEqual
(
loader
.
parse_filter_by_tags
([
'foo,bar,baz'
,
'-FOO,-BAR,-BAZ'
]),
[(
set
([
'foo'
,
'bar'
,
'baz'
]),
set
([])),
(
set
([]),
set
([
'FOO'
,
'BAR'
,
'BAZ'
]))])
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录