Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
817c25c2
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,发现更多精彩内容 >>
未验证
提交
817c25c2
编写于
4月 07, 2017
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'apahim/improve_docstring_tags_v2'
Signed-off-by:
N
Cleber Rosa
<
crosa@redhat.com
>
上级
a777a62d
033b8dc2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
66 deletion
+44
-66
avocado/core/loader.py
avocado/core/loader.py
+5
-5
avocado/core/safeloader.py
avocado/core/safeloader.py
+19
-40
docs/source/WritingTests.rst
docs/source/WritingTests.rst
+4
-0
selftests/unit/test_safeloader.py
selftests/unit/test_safeloader.py
+16
-21
未找到文件。
avocado/core/loader.py
浏览文件 @
817c25c2
...
...
@@ -611,14 +611,14 @@ class FileLoader(TestLoader):
docstring
=
ast
.
get_docstring
(
statement
)
# Looking for a class that has in the docstring either
# ":avocado: enable" or ":avocado: disable
if
safeloader
.
is_docstring_directive_disable
(
docstring
):
if
safeloader
.
check_docstring_directive
(
docstring
,
'disable'
):
continue
elif
safeloader
.
is_docstring_directive_enable
(
docstring
):
elif
safeloader
.
check_docstring_directive
(
docstring
,
'enable'
):
methods
=
[
st
.
name
for
st
in
statement
.
body
if
isinstance
(
st
,
ast
.
FunctionDef
)
and
st
.
name
.
startswith
(
'test'
)]
methods
=
data_structures
.
ordered_list_unique
(
methods
)
tags
=
safeloader
.
get_docstring_directive_tags
(
docstring
)
tags
=
safeloader
.
get_docstring_directive
s
_tags
(
docstring
)
result
[
statement
.
name
]
=
{
'methods'
:
methods
,
'tags'
:
tags
}
continue
...
...
@@ -632,7 +632,7 @@ class FileLoader(TestLoader):
isinstance
(
st
,
ast
.
FunctionDef
)
and
st
.
name
.
startswith
(
'test'
)]
methods
=
data_structures
.
ordered_list_unique
(
methods
)
tags
=
safeloader
.
get_docstring_directive_tags
(
docstring
)
tags
=
safeloader
.
get_docstring_directive
s
_tags
(
docstring
)
result
[
statement
.
name
]
=
{
'methods'
:
methods
,
'tags'
:
tags
}
continue
...
...
@@ -647,7 +647,7 @@ class FileLoader(TestLoader):
isinstance
(
st
,
ast
.
FunctionDef
)
and
st
.
name
.
startswith
(
'test'
)]
methods
=
data_structures
.
ordered_list_unique
(
methods
)
tags
=
safeloader
.
get_docstring_directive_tags
(
docstring
)
tags
=
safeloader
.
get_docstring_directive
s
_tags
(
docstring
)
result
[
statement
.
name
]
=
{
'methods'
:
methods
,
'tags'
:
tags
}
...
...
avocado/core/safeloader.py
浏览文件 @
817c25c2
...
...
@@ -68,65 +68,44 @@ def modules_imported_as(module):
AVOCADO_DOCSTRING_DIRECTIVE_RE
=
re
.
compile
(
r
'\s*:avocado:\s*(\S+)\s*'
)
def
get_docstring_directive
(
docstring
):
def
get_docstring_directive
s
(
docstring
):
"""
Returns the value
of the avocado docstring directive
Returns the value
s of the avocado docstring directives
:param docstring: the complete text used as documentation
:type docstring: str
"""
if
docstring
is
None
:
return
None
result
=
AVOCADO_DOCSTRING_DIRECTIVE_RE
.
search
(
docstring
)
if
result
is
not
None
:
return
result
.
groups
()[
0
]
def
is_docstring_directive_enable
(
docstring
):
:rtype: builtin.list
"""
Checks if there's a docstring directive that enables a Test class
:rtype: bool
"""
result
=
get_docstring_directive
(
docstring
)
return
result
==
'enable'
def
is_docstring_directive_disable
(
docstring
):
"""
Checks if there's a docstring directive that disables a Test class
:rtype: bool
"""
result
=
get_docstring_directive
(
docstring
)
return
result
==
'disable'
try
:
return
AVOCADO_DOCSTRING_DIRECTIVE_RE
.
findall
(
docstring
)
except
TypeError
:
return
[]
def
is_docstring_directive_tags
(
docstring
):
def
check_docstring_directive
(
docstring
,
directive
):
"""
Checks if there's a
docstring directive that tags a test
Checks if there's a
given directive in a given docstring
:rtype: bool
"""
result
=
get_docstring_directive
(
docstring
)
if
result
is
not
None
:
return
result
.
startswith
(
'tags='
)
return
False
return
directive
in
get_docstring_directives
(
docstring
)
def
get_docstring_directive_tags
(
docstring
):
def
get_docstring_directive
s
_tags
(
docstring
):
"""
Returns the test categories based on a `:avocado: tags=category` docstring
Returns the test categories based on a `:avocado: tags=category`
docstring
:rtype: set
"""
if
not
is_docstring_directive_tags
(
docstring
):
return
[]
tags
=
[]
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
])
raw_tag
=
get_docstring_directive
(
docstring
)
if
raw_tag
is
not
None
:
_
,
comma_tags
=
raw_tag
.
split
(
'tags='
,
1
)
return
set
([
tag
for
tag
in
comma_tags
.
split
(
','
)
if
tag
])
return
set
(
tags
)
def
find_class_and_methods
(
path
,
method_pattern
=
None
,
base_class
=
None
):
...
...
docs/source/WritingTests.rst
浏览文件 @
817c25c2
...
...
@@ -1238,6 +1238,10 @@ You can also use the ``:avocado: disable`` docstring directive, that
works the opposite way: something that would be considered an Avocado
test, but we force it to not be listed as one.
The docstring ``:avocado: disable`` is evaluated first by Avocado,
meaning that if both ``:avocado: disable`` and ``:avocado: enable`` are
present in the same docstring, the test will not be listed.
.. _categorizing-tests:
Categorizing tests
...
...
selftests/unit/test_safeloader.py
浏览文件 @
817c25c2
...
...
@@ -61,7 +61,9 @@ class DocstringDirectives(unittest.TestCase):
":avocado: tags=SLOW,disk, invalid"
:
set
([
"SLOW"
,
"disk"
]),
":avocado: tags=SLOW,disk , invalid"
:
set
([
"SLOW"
,
"disk"
]),
":avocado:
\t
tags=FAST"
:
set
([
"FAST"
]),
":avocado: tags="
:
set
([])}
":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. "
...
...
@@ -69,39 +71,34 @@ class DocstringDirectives(unittest.TestCase):
"mention avocado: it's awesome, but that was not a "
"directive. a tag would be something line this: "
":avocado: enable"
)
self
.
assertIsNotNone
(
safeloader
.
get_docstring_directive
(
docstring
))
self
.
assertIsNotNone
(
safeloader
.
get_docstring_directive
s
(
docstring
))
def
test_newlines
(
self
):
docstring
=
(
"
\n\n\n
This is a docstring with many new
\n\n
lines "
"followed by an avocado tag
\n
"
"
\n\n
:avocado: enable
\n\n
"
)
self
.
assertIsNotNone
(
safeloader
.
get_docstring_directive
(
docstring
))
self
.
assertIsNotNone
(
safeloader
.
get_docstring_directive
s
(
docstring
))
def
test_enabled
(
self
):
self
.
assertTrue
(
safeloader
.
is_docstring_directive_enable
(
":avocado: enable"
))
self
.
assertTrue
(
safeloader
.
is_docstring_directive_enable
(
":avocado:
\t
enable"
))
self
.
assertFalse
(
safeloader
.
is_docstring_directive_enable
(
":AVOCADO: ENABLE"
))
self
.
assertFalse
(
safeloader
.
is_docstring_directive_enable
(
":avocado: enabled"
))
self
.
assertTrue
(
safeloader
.
check_docstring_directive
(
":avocado: enable"
,
'enable'
))
self
.
assertTrue
(
safeloader
.
check_docstring_directive
(
":avocado:
\t
enable"
,
'enable'
))
self
.
assertTrue
(
safeloader
.
check_docstring_directive
(
":avocado: enable
\n
:avocado: tags=fast"
,
'enable'
))
self
.
assertFalse
(
safeloader
.
check_docstring_directive
(
":AVOCADO: ENABLE"
,
'enable'
))
self
.
assertFalse
(
safeloader
.
check_docstring_directive
(
":avocado: enabled"
,
'enable'
))
def
test_disabled
(
self
):
self
.
assertTrue
(
safeloader
.
is_docstring_directive_disable
(
":avocado: disable"
))
self
.
assertTrue
(
safeloader
.
is_docstring_directive_disable
(
":avocado:
\t
disable"
))
self
.
assertFalse
(
safeloader
.
is_docstring_directive_disable
(
":AVOCADO: DISABLE"
))
self
.
assertFalse
(
safeloader
.
is_docstring_directive_disable
(
":avocado: disabled"
))
def
test_is_tags
(
self
):
for
tag
in
self
.
VALID_TAGS
:
self
.
assertTrue
(
safeloader
.
is_docstring_directive_tags
(
tag
))
for
tag
in
self
.
NO_TAGS
:
self
.
assertFalse
(
safeloader
.
is_docstring_directive_tags
(
tag
))
self
.
assertTrue
(
safeloader
.
check_docstring_directive
(
":avocado: disable"
,
'disable'
))
self
.
assertTrue
(
safeloader
.
check_docstring_directive
(
":avocado:
\t
disable"
,
'disable'
))
self
.
assertFalse
(
safeloader
.
check_docstring_directive
(
":AVOCADO: DISABLE"
,
'disable'
))
self
.
assertFalse
(
safeloader
.
check_docstring_directive
(
":avocado: disabled"
,
'disable'
))
def
test_get_tags_empty
(
self
):
for
tag
in
self
.
NO_TAGS
:
self
.
assertEqual
(
[],
safeloader
.
get_docstring_directive
_tags
(
tag
))
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_directive_tags
(
raw
),
tags
)
self
.
assertEqual
(
safeloader
.
get_docstring_directive
s
_tags
(
raw
),
tags
)
class
UnlimitedDiff
(
unittest
.
TestCase
):
...
...
@@ -128,7 +125,6 @@ class FindClassAndMethods(UnlimitedDiff):
'test_newlines'
,
'test_enabled'
,
'test_disabled'
,
'test_is_tags'
,
'test_get_tags_empty'
,
'test_get_tags'
],
'FindClassAndMethods'
:
[
'test_self'
,
...
...
@@ -150,7 +146,6 @@ class FindClassAndMethods(UnlimitedDiff):
'test_newlines'
,
'test_enabled'
,
'test_disabled'
,
'test_is_tags'
,
'test_get_tags_empty'
,
'test_get_tags'
],
'FindClassAndMethods'
:
[
'test_self'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录