Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
cd8f6bc4
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,发现更多精彩内容 >>
提交
cd8f6bc4
编写于
7月 07, 2015
作者:
L
Lucas Meneghel Rodrigues
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #717 from ldoktor/fail_on3
avocado.core.exceptions: Update fail_on_error and rename to fail_on
上级
02e8a4ce
f672733e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
30 deletion
+47
-30
avocado/__init__.py
avocado/__init__.py
+2
-2
avocado/core/exceptions.py
avocado/core/exceptions.py
+39
-23
examples/tests/fail_on_exception.py
examples/tests/fail_on_exception.py
+4
-3
selftests/all/functional/avocado/basic_tests.py
selftests/all/functional/avocado/basic_tests.py
+2
-2
未找到文件。
avocado/__init__.py
浏览文件 @
cd8f6bc4
...
...
@@ -13,10 +13,10 @@
# Author: Lucas Meneghel Rodrigues <lmr@redhat.com>
__all__
=
[
'main'
,
'Test'
,
'VERSION'
,
'fail_on
_error
'
]
__all__
=
[
'main'
,
'Test'
,
'VERSION'
,
'fail_on'
]
from
avocado.core.job
import
main
from
avocado.core.test
import
Test
from
avocado.core.version
import
VERSION
from
avocado.core.exceptions
import
fail_on
_error
from
avocado.core.exceptions
import
fail_on
avocado/core/exceptions.py
浏览文件 @
cd8f6bc4
...
...
@@ -15,29 +15,45 @@
"""
Exception classes, useful for tests, and other parts of the framework code.
"""
def
fail_on_error
(
fn
):
"""
Apply to any test you want to FAIL upon any exception raised.
Normally only TestFail called explicitly will mark an avocado test with the
FAIL state, but this decorator is provided as a convenience for people
that need a more relaxed behavior.
:param fn: Function that will be decorated
"""
def
new_fn
(
*
args
,
**
kwargs
):
try
:
return
fn
(
*
args
,
**
kwargs
)
except
TestBaseException
:
raise
except
Exception
,
e
:
raise
TestFail
(
str
(
e
))
new_fn
.
__name__
=
fn
.
__name__
new_fn
.
__doc__
=
fn
.
__doc__
new_fn
.
__dict__
.
update
(
fn
.
__dict__
)
return
new_fn
from
functools
import
wraps
import
types
def
fail_on
(
exceptions
=
None
):
"""
Fail the test when decorated function produces exception of the specified
type.
(For example, our method may raise IndexError on tested software failure.
We can either try/catch it or use this decorator instead)
:param exceptions: Tuple or single exception to be assumed as
test fail [Exception]
:note: self.error and self.skip behavior remains intact
:note: To allow simple usage param "exceptions" must not be callable
"""
func
=
False
if
exceptions
is
None
:
exceptions
=
Exception
elif
isinstance
(
exceptions
,
types
.
FunctionType
):
# @fail_on without ()
func
=
exceptions
exceptions
=
Exception
def
decorate
(
func
):
""" Decorator """
@
wraps
(
func
)
def
wrap
(
*
args
,
**
kwargs
):
""" Function wrapper """
try
:
return
func
(
*
args
,
**
kwargs
)
except
TestBaseException
:
raise
except
exceptions
,
details
:
raise
TestFail
(
str
(
details
))
return
wrap
if
func
:
return
decorate
(
func
)
return
decorate
class
JobBaseException
(
Exception
):
...
...
examples/tests/fail_on_e
rror
.py
→
examples/tests/fail_on_e
xception
.py
浏览文件 @
cd8f6bc4
...
...
@@ -3,13 +3,14 @@
import
avocado
class
FailOnE
rror
(
avocado
.
Test
):
class
FailOnE
xception
(
avocado
.
Test
):
"""
Test illustrating the behavior of the fail_on
_error
decorator.
Test illustrating the behavior of the fail_on decorator.
"""
@
avocado
.
fail_on_error
# @avocado.fail_on(ValueError) also possible
@
avocado
.
fail_on
def
test
(
self
):
"""
This should end with FAIL.
...
...
selftests/all/functional/avocado/basic_tests.py
浏览文件 @
cd8f6bc4
...
...
@@ -126,10 +126,10 @@ class RunnerOperationTest(unittest.TestCase):
result
))
self
.
assertIn
(
'"status": "ERROR"'
,
result
.
stdout
)
def
test_fail_on_e
rror
(
self
):
def
test_fail_on_e
xception
(
self
):
os
.
chdir
(
basedir
)
cmd_line
=
(
"./scripts/avocado run --sysinfo=off --job-results-dir %s "
"--json - fail_on_e
rror
"
%
self
.
tmpdir
)
"--json - fail_on_e
xception
"
%
self
.
tmpdir
)
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_rc
=
1
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录