Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
02314957
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,发现更多精彩内容 >>
未验证
提交
02314957
编写于
12月 12, 2018
作者:
C
Caio Carrara
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'clebergnu/tags_key_val_prep'
Signed-off-by:
N
Caio Carrara
<
ccarrara@redhat.com
>
上级
02325f6c
b0a67c1e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
133 addition
and
44 deletion
+133
-44
avocado/core/loader.py
avocado/core/loader.py
+12
-8
avocado/core/safeloader.py
avocado/core/safeloader.py
+14
-5
selftests/unit/test_loader.py
selftests/unit/test_loader.py
+18
-9
selftests/unit/test_safeloader.py
selftests/unit/test_safeloader.py
+89
-22
未找到文件。
avocado/core/loader.py
浏览文件 @
02314957
...
...
@@ -81,22 +81,26 @@ def filter_test_tags(test_suite, filter_by_tags, include_empty=False):
"""
filtered
=
[]
for
klass
,
info
in
test_suite
:
test_tags
=
info
.
get
(
'tags'
,
set
([])
)
test_tags
=
info
.
get
(
'tags'
,
{}
)
if
not
test_tags
and
include_empty
:
filtered
.
append
((
klass
,
info
))
continue
for
raw_tags
in
filter_by_tags
:
required_tags
=
raw_tags
.
split
(
','
)
must_not_have_tags
=
set
([
_
[
1
:]
for
_
in
required_tags
if
_
.
startswith
(
'-'
)])
if
must_not_have_tags
.
intersection
(
test_tags
):
must
=
set
()
must_not
=
set
()
for
tag
in
required_tags
:
if
tag
.
startswith
(
'-'
):
must_not
.
add
(
tag
[
1
:])
else
:
must
.
add
(
tag
)
if
must_not
.
intersection
(
test_tags
):
continue
must_have_tags
=
set
([
_
for
_
in
required_tags
if
not
_
.
startswith
(
'-'
)])
if
must_have_tags
:
if
not
must_have_tags
.
issubset
(
test_tags
):
if
must
:
if
not
must
.
issubset
(
test_tags
):
continue
filtered
.
append
((
klass
,
info
))
...
...
avocado/core/safeloader.py
浏览文件 @
02314957
...
...
@@ -167,15 +167,24 @@ def get_docstring_directives_tags(docstring):
Returns the test categories based on a `:avocado: tags=category`
docstring
:rtype:
se
t
:rtype:
dic
t
"""
tags
=
[]
result
=
{}
for
item
in
get_docstring_directives
(
docstring
):
if
item
.
startswith
(
'tags='
):
_
,
comma_tags
=
item
.
split
(
'tags='
,
1
)
tags
.
extend
([
tag
for
tag
in
comma_tags
.
split
(
','
)
if
tag
])
return
set
(
tags
)
for
tag
in
comma_tags
.
split
(
','
):
if
not
tag
:
continue
if
':'
in
tag
:
key
,
val
=
tag
.
split
(
':'
,
1
)
if
key
in
result
:
result
[
key
].
add
(
val
)
else
:
result
[
key
]
=
set
([
val
])
else
:
result
[
tag
]
=
None
return
result
def
find_class_and_methods
(
path
,
method_pattern
=
None
,
base_class
=
None
):
...
...
selftests/unit/test_loader.py
浏览文件 @
02314957
...
...
@@ -93,6 +93,13 @@ class SafeTest(Test):
def test_safe(self):
pass
class SafeX86Test(Test):
'''
:avocado: tags=safe,arch:x86_64
'''
def test_safe_x86(self):
pass
if __name__ == "__main__":
main()
"""
...
...
@@ -437,7 +444,7 @@ class TagFilter(unittest.TestCase):
loader
.
DiscoverMode
.
ALL
)
def
test_no_tag_filter
(
self
):
self
.
assertEqual
(
len
(
self
.
test_suite
),
5
)
self
.
assertEqual
(
len
(
self
.
test_suite
),
6
)
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'
)
...
...
@@ -486,7 +493,7 @@ class TagFilter(unittest.TestCase):
def
test_filter_not_fast_not_slow
(
self
):
filtered
=
loader
.
filter_test_tags
(
self
.
test_suite
,
[
'-fast,-slow'
])
self
.
assertEqual
(
len
(
filtered
),
1
)
self
.
assertEqual
(
len
(
filtered
),
2
)
self
.
assertEqual
(
filtered
[
0
][
0
],
'SafeTest'
)
self
.
assertEqual
(
filtered
[
0
][
1
][
'methodName'
],
'test_safe'
)
...
...
@@ -502,13 +509,15 @@ class TagFilter(unittest.TestCase):
self
.
assertEqual
(
len
(
filtered
),
0
)
def
test_load_tags
(
self
):
tags_map
=
{
'FastTest.test_fast'
:
set
([
'fast'
,
'net'
]),
'FastTest.test_fast_other'
:
set
([
'fast'
,
'net'
]),
'SlowTest.test_slow'
:
set
([
'slow'
,
'disk'
]),
'SlowUnsafeTest.test_slow_unsafe'
:
set
([
'slow'
,
'disk'
,
'unsafe'
]),
'SafeTest.test_safe'
:
set
([
'safe'
])}
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'
])}}
for
_
,
info
in
self
.
test_suite
:
name
=
info
[
'name'
].
split
(
':'
,
1
)[
1
]
...
...
selftests/unit/test_safeloader.py
浏览文件 @
02314957
...
...
@@ -133,17 +133,6 @@ class DocstringDirectives(unittest.TestCase):
":avocado: tags=SLOW,disk, invalid"
,
":avocado: tags=SLOW,disk , invalid"
]
VALID_TAGS
=
{
":avocado: tags=fast"
:
set
([
"fast"
]),
":avocado: tags=fast,network"
:
set
([
"fast"
,
"network"
]),
":avocado: tags=fast,,network"
:
set
([
"fast"
,
"network"
]),
":avocado: tags=slow,DISK"
:
set
([
"slow"
,
"DISK"
]),
":avocado: tags=SLOW,disk,disk"
:
set
([
"SLOW"
,
"disk"
]),
":avocado:
\t
tags=FAST"
:
set
([
"FAST"
]),
":avocado: tags="
:
set
([]),
":avocado: enable
\n
:avocado: tags=fast"
:
set
([
"fast"
]),
":avocado: tags=fast,slow
\n
:avocado: enable"
:
set
([
"fast"
,
"slow"
])
}
def
test_longline
(
self
):
docstring
=
(
"This is a very long docstring in a single line. "
"Since we have nothing useful to put in here let's just "
...
...
@@ -173,11 +162,67 @@ class DocstringDirectives(unittest.TestCase):
def
test_get_tags_empty
(
self
):
for
tag
in
self
.
NO_TAGS
:
self
.
assertEqual
(
set
([]),
safeloader
.
get_docstring_directives_tags
(
tag
))
def
test_get_tags
(
self
):
for
raw
,
tags
in
self
.
VALID_TAGS
.
items
():
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
tags
)
self
.
assertEqual
({},
safeloader
.
get_docstring_directives_tags
(
tag
))
def
test_tag_single
(
self
):
raw
=
":avocado: tags=fast"
exp
=
{
"fast"
:
None
}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_double
(
self
):
raw
=
":avocado: tags=fast,network"
exp
=
{
"fast"
:
None
,
"network"
:
None
}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_double_with_empty
(
self
):
raw
=
":avocado: tags=fast,,network"
exp
=
{
"fast"
:
None
,
"network"
:
None
}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_lowercase_uppercase
(
self
):
raw
=
":avocado: tags=slow,DISK"
exp
=
{
"slow"
:
None
,
"DISK"
:
None
}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_duplicate
(
self
):
raw
=
":avocado: tags=SLOW,disk,disk"
exp
=
{
"SLOW"
:
None
,
"disk"
:
None
}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_tab_separator
(
self
):
raw
=
":avocado:
\t
tags=FAST"
exp
=
{
"FAST"
:
None
}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_empty
(
self
):
raw
=
":avocado: tags="
exp
=
{}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_newline_before
(
self
):
raw
=
":avocado: enable
\n
:avocado: tags=fast"
exp
=
{
"fast"
:
None
}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_newline_after
(
self
):
raw
=
":avocado: tags=fast,slow
\n
:avocado: enable"
exp
=
{
"fast"
:
None
,
"slow"
:
None
}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_keyval_single
(
self
):
raw
=
":avocado: tags=fast,arch:x86_64"
exp
=
{
"fast"
:
None
,
"arch"
:
set
([
"x86_64"
])}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_keyval_double
(
self
):
raw
=
":avocado: tags=fast,arch:x86_64,arch:ppc64"
exp
=
{
"fast"
:
None
,
"arch"
:
set
([
"x86_64"
,
"ppc64"
])}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_tag_keyval_duplicate
(
self
):
raw
=
":avocado: tags=fast,arch:x86_64,arch:ppc64,arch:x86_64"
exp
=
{
"fast"
:
None
,
"arch"
:
set
([
"x86_64"
,
"ppc64"
])}
self
.
assertEqual
(
safeloader
.
get_docstring_directives_tags
(
raw
),
exp
)
def
test_directives_regex
(
self
):
"""
...
...
@@ -214,7 +259,18 @@ class FindClassAndMethods(UnlimitedDiff):
'test_enabled'
,
'test_disabled'
,
'test_get_tags_empty'
,
'test_get_tags'
,
'test_tag_single'
,
'test_tag_double'
,
'test_tag_double_with_empty'
,
'test_tag_lowercase_uppercase'
,
'test_tag_duplicate'
,
'test_tag_tab_separator'
,
'test_tag_empty'
,
'test_tag_newline_before'
,
'test_tag_newline_after'
,
'test_tag_keyval_single'
,
'test_tag_keyval_double'
,
'test_tag_keyval_duplicate'
,
'test_directives_regex'
],
'FindClassAndMethods'
:
[
'test_self'
,
'test_with_pattern'
,
...
...
@@ -238,7 +294,18 @@ class FindClassAndMethods(UnlimitedDiff):
'test_enabled'
,
'test_disabled'
,
'test_get_tags_empty'
,
'test_get_tags'
,
'test_tag_single'
,
'test_tag_double'
,
'test_tag_double_with_empty'
,
'test_tag_lowercase_uppercase'
,
'test_tag_duplicate'
,
'test_tag_tab_separator'
,
'test_tag_empty'
,
'test_tag_newline_before'
,
'test_tag_newline_after'
,
'test_tag_keyval_single'
,
'test_tag_keyval_double'
,
'test_tag_keyval_duplicate'
,
'test_directives_regex'
],
'FindClassAndMethods'
:
[
'test_self'
,
'test_with_pattern'
,
...
...
@@ -299,10 +366,10 @@ class FindClassAndMethods(UnlimitedDiff):
sys
.
path
.
append
(
os
.
path
.
dirname
(
avocado_recursive_discovery_test1
.
path
))
tests
=
safeloader
.
find_avocado_tests
(
avocado_recursive_discovery_test2
.
path
)[
0
]
expected
=
{
'ThirdChild'
:
[(
'test_third_child'
,
set
([])
),
(
'test_second_child'
,
set
([])
),
(
'test_first_child'
,
set
([])
),
(
'test_basic'
,
set
([])
)]}
expected
=
{
'ThirdChild'
:
[(
'test_third_child'
,
{}
),
(
'test_second_child'
,
{}
),
(
'test_first_child'
,
{}
),
(
'test_basic'
,
{}
)]}
self
.
assertEqual
(
expected
,
tests
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录