Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
d886f55b
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,发现更多精彩内容 >>
提交
d886f55b
编写于
4月 08, 2015
作者:
L
Lucas Meneghel Rodrigues
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #528 from ruda/multiple_tests_V3
Support for multiple tests [V3]
上级
d720b2d8
a107348c
变更
38
隐藏空白更改
内联
并排
Showing
38 changed file
with
244 addition
and
176 deletion
+244
-176
avocado/job.py
avocado/job.py
+16
-1
avocado/loader.py
avocado/loader.py
+55
-26
avocado/plugins/runner.py
avocado/plugins/runner.py
+0
-3
avocado/plugins/test_list.py
avocado/plugins/test_list.py
+1
-0
avocado/test.py
avocado/test.py
+29
-28
docs/source/DebuggingWithGDB.rst
docs/source/DebuggingWithGDB.rst
+2
-2
docs/source/WritingTests.rst
docs/source/WritingTests.rst
+10
-10
examples/tests/abort.py
examples/tests/abort.py
+1
-1
examples/tests/cabort.py
examples/tests/cabort.py
+2
-2
examples/tests/datadir.py
examples/tests/datadir.py
+2
-2
examples/tests/doublefail.py
examples/tests/doublefail.py
+3
-3
examples/tests/doublefree.py
examples/tests/doublefree.py
+2
-2
examples/tests/doublefree_nasty.py
examples/tests/doublefree_nasty.py
+2
-2
examples/tests/errortest.py
examples/tests/errortest.py
+1
-1
examples/tests/failtest.py
examples/tests/failtest.py
+1
-1
examples/tests/failtest_nasty.py
examples/tests/failtest_nasty.py
+1
-1
examples/tests/failtest_nasty2.py
examples/tests/failtest_nasty2.py
+1
-1
examples/tests/fiotest.py
examples/tests/fiotest.py
+2
-2
examples/tests/gdbtest.py
examples/tests/gdbtest.py
+1
-27
examples/tests/gendata.py
examples/tests/gendata.py
+1
-1
examples/tests/linuxbuild.py
examples/tests/linuxbuild.py
+2
-2
examples/tests/modify_variable.py
examples/tests/modify_variable.py
+2
-2
examples/tests/multiplextest.py
examples/tests/multiplextest.py
+2
-2
examples/tests/passtest.py
examples/tests/passtest.py
+1
-1
examples/tests/raise.py
examples/tests/raise.py
+2
-2
examples/tests/skiptest.py
examples/tests/skiptest.py
+1
-1
examples/tests/sleeptenmin.py
examples/tests/sleeptenmin.py
+1
-1
examples/tests/sleeptest.py
examples/tests/sleeptest.py
+1
-1
examples/tests/synctest.py
examples/tests/synctest.py
+2
-2
examples/tests/timeouttest.py
examples/tests/timeouttest.py
+1
-1
examples/tests/trinity.py
examples/tests/trinity.py
+2
-2
examples/tests/warntest.py
examples/tests/warntest.py
+1
-1
examples/tests/whiteboard.py
examples/tests/whiteboard.py
+1
-1
selftests/all/functional/avocado/basic_tests.py
selftests/all/functional/avocado/basic_tests.py
+1
-1
selftests/all/functional/avocado/loader_tests.py
selftests/all/functional/avocado/loader_tests.py
+2
-2
selftests/all/unit/avocado/loader_unittest.py
selftests/all/unit/avocado/loader_unittest.py
+43
-22
selftests/all/unit/avocado/multiples_tests.py
selftests/all/unit/avocado/multiples_tests.py
+35
-0
selftests/all/unit/avocado/test_unittest.py
selftests/all/unit/avocado/test_unittest.py
+11
-16
未找到文件。
avocado/job.py
浏览文件 @
d886f55b
...
...
@@ -24,6 +24,7 @@ import sys
import
traceback
import
tempfile
import
shutil
import
fnmatch
from
avocado
import
multiplexer
from
avocado
import
result
...
...
@@ -268,9 +269,23 @@ class Job(object):
e_msg
=
'
\n
'
.
join
(
error_msg_parts
)
raise
exceptions
.
OptionValidationError
(
e_msg
)
# Filter tests methods with params.filter and methodName
filtered_suite
=
[]
for
test_template
in
test_suite
:
test_factory
,
test_parameters
=
test_template
filter_pattern
=
test_parameters
[
'params'
].
get
(
'filter'
,
None
)
method
=
test_parameters
.
get
(
'methodName'
)
if
not
filter_pattern
:
filtered_suite
.
append
(
test_template
)
else
:
if
method
and
fnmatch
.
fnmatch
(
method
,
filter_pattern
):
filtered_suite
.
append
(
test_template
)
test_suite
=
filtered_suite
if
not
test_suite
:
e_msg
=
(
"No tests found within the specified path(s) "
"(Possible reasons: File ownership, permissions, typos)"
)
"(Possible reasons: File ownership, permissions, "
"filters, typos)"
)
raise
exceptions
.
OptionValidationError
(
e_msg
)
self
.
args
.
test_result_total
=
mux
.
get_number_of_tests
(
test_suite
)
...
...
avocado/loader.py
浏览文件 @
d886f55b
...
...
@@ -53,6 +53,19 @@ class TestLoader(object):
job
=
_DebugJob
()
self
.
job
=
job
def
_is_unittests_like
(
self
,
test_class
,
pattern
=
'test'
):
for
name
,
_
in
inspect
.
getmembers
(
test_class
,
inspect
.
ismethod
):
if
name
.
startswith
(
pattern
):
return
True
return
False
def
_make_unittests_like
(
self
,
test_class
,
pattern
=
'test'
):
test_methods
=
[]
for
name
,
obj
in
inspect
.
getmembers
(
test_class
,
inspect
.
ismethod
):
if
name
.
startswith
(
pattern
):
test_methods
.
append
((
name
,
obj
))
return
test_methods
def
_make_missing_test
(
self
,
test_name
,
params
):
test_class
=
test
.
MissingTest
test_parameters
=
{
'name'
:
test_name
,
...
...
@@ -77,7 +90,7 @@ class TestLoader(object):
'job'
:
self
.
job
}
return
test_class
,
test_parameters
def
_make_test
(
self
,
test_name
,
test_path
,
params
):
def
_make_test
s
(
self
,
test_name
,
test_path
,
params
):
module_name
=
os
.
path
.
basename
(
test_path
).
split
(
'.'
)[
0
]
test_module_dir
=
os
.
path
.
dirname
(
test_path
)
sys
.
path
.
append
(
test_module_dir
)
...
...
@@ -103,7 +116,17 @@ class TestLoader(object):
if
test_class
is
not
None
:
# Module is importable and does have an avocado test class
# inside, let's proceed.
test_parameters
=
test_parameters_name
if
self
.
_is_unittests_like
(
test_class
):
test_factories
=
[]
for
test_method
in
self
.
_make_unittests_like
(
test_class
):
copy_test_parameters_name
=
test_parameters_name
.
copy
()
copy_test_parameters_name
[
'methodName'
]
=
test_method
[
0
]
class_and_method_name
=
':%s.%s'
%
(
test_class
.
__name__
,
test_method
[
0
])
copy_test_parameters_name
[
'name'
]
+=
class_and_method_name
test_factories
.
append
([
test_class
,
copy_test_parameters_name
])
return
test_factories
else
:
test_parameters
=
test_parameters_name
else
:
if
os
.
access
(
test_path
,
os
.
X_OK
):
# Module does not have an avocado test class inside but
...
...
@@ -147,27 +170,26 @@ class TestLoader(object):
sys
.
path
.
pop
(
sys
.
path
.
index
(
test_module_dir
))
return
test_class
,
test_parameters
return
[(
test_class
,
test_parameters
)]
def
discover_test
(
self
,
params
):
def
discover_test
s
(
self
,
params
):
"""
Try to discover and resolve
a test
.
Try to discover and resolve
tests
.
:param params: dictionary with test parameters.
:type params: dict
:return: a test factory (a pair of test class and test parameters)
or `None`.
:return: a list of test factories (a pair of test class and test parameters).
"""
test_name
=
test_path
=
params
.
get
(
'id'
)
if
os
.
path
.
exists
(
test_path
):
if
os
.
access
(
test_path
,
os
.
R_OK
)
is
False
:
return
(
AccessDeniedPath
,
{
'params'
:
{
'id'
:
test_path
}})
return
[(
AccessDeniedPath
,
{
'params'
:
{
'id'
:
test_path
}})]
path_analyzer
=
path
.
PathInspector
(
test_path
)
if
path_analyzer
.
is_python
():
test_class
,
test_parameters
=
self
.
_make_test
(
test_name
,
test_path
,
params
)
test_factories
=
self
.
_make_tests
(
test_name
,
test_path
,
params
)
return
test_factories
else
:
if
os
.
access
(
test_path
,
os
.
X_OK
):
test_class
,
test_parameters
=
self
.
_make_simple_test
(
test_path
,
...
...
@@ -179,21 +201,20 @@ class TestLoader(object):
if
os
.
path
.
islink
(
test_path
):
try
:
if
not
os
.
path
.
isfile
(
os
.
readlink
(
test_path
)):
return
BrokenSymlink
,
{
'params'
:
{
'id'
:
test_path
}}
return
[(
BrokenSymlink
,
{
'params'
:
{
'id'
:
test_path
}})]
except
OSError
:
return
AccessDeniedPath
,
{
'params'
:
{
'id'
:
test_path
}}
return
[(
AccessDeniedPath
,
{
'params'
:
{
'id'
:
test_path
}})]
# Try to resolve test ID (keep compatibility)
rel_path
=
'%s.py'
%
test_name
test_path
=
os
.
path
.
join
(
data_dir
.
get_test_dir
(),
rel_path
)
if
os
.
path
.
exists
(
test_path
):
test_class
,
test_parameters
=
self
.
_make_test
(
rel_path
,
test_path
,
params
)
test_factories
=
self
.
_make_tests
(
rel_path
,
test_path
,
params
)
return
test_factories
else
:
test_class
,
test_parameters
=
self
.
_make_missing_test
(
test_name
,
params
)
return
test_class
,
test_parameters
return
[(
test_class
,
test_parameters
)]
def
discover_url
(
self
,
url
):
"""
...
...
@@ -212,6 +233,12 @@ class TestLoader(object):
'__main__.py'
)
params_list
=
[]
# Look for filename:test_method pattern
if
':'
in
url
:
url
,
filter_pattern
=
url
.
split
(
':'
,
1
)
else
:
filter_pattern
=
None
def
onerror
(
exception
):
norm_url
=
os
.
path
.
abspath
(
url
)
norm_error_filename
=
os
.
path
.
abspath
(
exception
.
filename
)
...
...
@@ -221,6 +248,7 @@ class TestLoader(object):
omit_non_tests
=
False
params_list
.
append
({
'id'
:
exception
.
filename
,
'filter'
:
filter_pattern
,
'omit_non_tests'
:
omit_non_tests
})
for
dirpath
,
dirnames
,
filenames
in
os
.
walk
(
url
,
onerror
=
onerror
):
...
...
@@ -264,15 +292,16 @@ class TestLoader(object):
"""
test_suite
=
[]
for
params
in
params_list
:
test_factory
=
self
.
discover_test
(
params
)
if
test_factory
is
None
:
continue
test_class
,
test_parameters
=
test_factory
if
test_class
in
[
test
.
NotATest
,
BrokenSymlink
,
AccessDeniedPath
]:
if
not
params
.
get
(
'omit_non_tests'
):
test_factories
=
self
.
discover_tests
(
params
)
for
test_factory
in
test_factories
:
if
test_factory
is
None
:
continue
test_class
,
test_parameters
=
test_factory
if
test_class
in
[
test
.
NotATest
,
BrokenSymlink
,
AccessDeniedPath
]:
if
not
params
.
get
(
'omit_non_tests'
):
test_suite
.
append
((
test_class
,
test_parameters
))
else
:
test_suite
.
append
((
test_class
,
test_parameters
))
else
:
test_suite
.
append
((
test_class
,
test_parameters
))
return
test_suite
@
staticmethod
...
...
avocado/plugins/runner.py
浏览文件 @
d886f55b
...
...
@@ -139,7 +139,4 @@ class TestRunner(plugin.Plugin):
job_instance
=
job
.
Job
(
args
)
rc
=
job_instance
.
run
()
if
not
args
.
url
:
self
.
parser
.
print_help
()
return
rc
avocado/plugins/test_list.py
浏览文件 @
d886f55b
...
...
@@ -129,6 +129,7 @@ class TestList(plugin.Plugin):
else
:
if
issubclass
(
cls
,
test
.
Test
):
stats
[
'instrumented'
]
+=
1
id_label
=
params
[
'name'
]
type_label
=
self
.
term_support
.
healthy_str
(
'INSTRUMENTED'
)
test_matrix
.
append
((
type_label
,
id_label
))
...
...
avocado/test.py
浏览文件 @
d886f55b
...
...
@@ -48,7 +48,7 @@ class Test(unittest.TestCase):
Base implementation for the test class.
You'll inherit from this to write your own tests. Typically you'll want
to implement set
up(), action() and cleanup
() methods on your own tests.
to implement set
Up(), runTest() and tearDown
() methods on your own tests.
"""
default_params
=
{}
...
...
@@ -94,8 +94,9 @@ class Test(unittest.TestCase):
tmpdir
=
data_dir
.
get_tmp_dir
()
self
.
basedir
=
os
.
path
.
dirname
(
inspect
.
getfile
(
self
.
__class__
))
self
.
datadir
=
os
.
path
.
join
(
self
.
basedir
,
'%s.data'
%
basename
)
self
.
filename
=
inspect
.
getfile
(
self
.
__class__
).
rstrip
(
'co'
)
self
.
basedir
=
os
.
path
.
dirname
(
self
.
filename
)
self
.
datadir
=
utils_path
.
init_dir
(
self
.
filename
+
'.data'
)
self
.
expected_stdout_file
=
os
.
path
.
join
(
self
.
datadir
,
'stdout.expected'
)
...
...
@@ -181,7 +182,7 @@ class Test(unittest.TestCase):
self
.
runner_queue
=
runner_queue
self
.
time_elapsed
=
None
unittest
.
TestCase
.
__init__
(
self
)
unittest
.
TestCase
.
__init__
(
self
,
methodName
=
methodName
)
def
__str__
(
self
):
return
str
(
self
.
name
)
...
...
@@ -312,9 +313,9 @@ class Test(unittest.TestCase):
return
tagged_name
def
set
u
p
(
self
):
def
set
U
p
(
self
):
"""
Setup stage that the test needs before passing to the actual
action
.
Setup stage that the test needs before passing to the actual
runTest
.
Must be implemented by tests if they want such an stage. Commonly we'll
download/compile test suites, create files needed for a test, among
...
...
@@ -322,7 +323,7 @@ class Test(unittest.TestCase):
"""
pass
def
action
(
self
):
def
runTest
(
self
):
"""
Actual test payload. Must be implemented by tests.
...
...
@@ -331,14 +332,13 @@ class Test(unittest.TestCase):
operations decide if the test pass (let the test complete) or fail
(raise a test related exception).
"""
raise
NotImplementedError
(
'Test subclasses must implement an action '
'method'
)
pass
def
cleanup
(
self
):
def
tearDown
(
self
):
"""
Cleanup stage after the
action
is done.
Cleanup stage after the
runTest
is done.
Examples of cleanup
action
s are deleting temporary files, restoring
Examples of cleanup
runTest
s are deleting temporary files, restoring
firewall configurations or other system settings that were changed
in setup.
"""
...
...
@@ -368,31 +368,32 @@ class Test(unittest.TestCase):
'Actual:
\n
%s
\n
Expected:
\n
%s'
%
(
actual
,
expected
))
self
.
assertEqual
(
expected
,
actual
,
msg
)
def
run
Test
(
self
,
result
=
None
):
def
run
(
self
,
result
=
None
):
"""
Run test method, for compatibility with unittest.TestCase.
:result: Unused param, compatibiltiy with :class:`unittest.TestCase`.
"""
testMethod
=
getattr
(
self
,
self
.
_testMethodName
)
self
.
start_logging
()
self
.
sysinfo_logger
.
start_test_hook
()
action
_exception
=
None
runTest
_exception
=
None
cleanup_exception
=
None
stdout_check_exception
=
None
stderr_check_exception
=
None
try
:
self
.
set
u
p
()
self
.
set
U
p
()
except
Exception
,
details
:
stacktrace
.
log_exc_info
(
sys
.
exc_info
(),
logger
=
'avocado.test'
)
raise
exceptions
.
TestSetupFail
(
details
)
try
:
self
.
action
()
testMethod
()
except
Exception
,
details
:
stacktrace
.
log_exc_info
(
sys
.
exc_info
(),
logger
=
'avocado.test'
)
action
_exception
=
details
runTest
_exception
=
details
finally
:
try
:
self
.
cleanup
()
self
.
tearDown
()
except
Exception
,
details
:
stacktrace
.
log_exc_info
(
sys
.
exc_info
(),
logger
=
'avocado.test'
)
cleanup_exception
=
details
...
...
@@ -429,8 +430,8 @@ class Test(unittest.TestCase):
self
.
record_reference_stderr
()
# pylint: disable=E0702
if
action
_exception
is
not
None
:
raise
action
_exception
if
runTest
_exception
is
not
None
:
raise
runTest
_exception
elif
cleanup_exception
is
not
None
:
raise
exceptions
.
TestSetupFail
(
cleanup_exception
)
elif
stdout_check_exception
is
not
None
:
...
...
@@ -458,14 +459,14 @@ class Test(unittest.TestCase):
def
run_avocado
(
self
,
result
=
None
):
"""
Wraps the run
Test
method, for execution inside the avocado runner.
Wraps the run method, for execution inside the avocado runner.
:result: Unused param, compatibility with :class:`unittest.TestCase`.
"""
self
.
_setup_environment_variables
()
try
:
self
.
tag_start
()
self
.
run
Test
(
result
)
self
.
run
(
result
)
except
exceptions
.
TestBaseException
,
detail
:
self
.
status
=
detail
.
status
self
.
fail_class
=
detail
.
__class__
.
__name__
...
...
@@ -545,7 +546,7 @@ class SimpleTest(Test):
self
.
log
.
info
(
"Exit status: %s"
,
result
.
exit_status
)
self
.
log
.
info
(
"Duration: %s"
,
result
.
duration
)
def
action
(
self
):
def
runTest
(
self
):
"""
Run the executable, and log its detailed execution.
"""
...
...
@@ -560,8 +561,8 @@ class SimpleTest(Test):
self
.
_log_detailed_cmd_info
(
details
.
result
)
raise
exceptions
.
TestFail
(
details
)
def
run
Test
(
self
,
result
=
None
):
super
(
SimpleTest
,
self
).
run
Test
(
result
)
def
run
(
self
,
result
=
None
):
super
(
SimpleTest
,
self
).
run
(
result
)
for
line
in
open
(
self
.
logfile
):
if
self
.
re_avocado_log
.
match
(
line
):
raise
exceptions
.
TestWarn
(
"Test passed but there were warnings"
...
...
@@ -582,7 +583,7 @@ class MissingTest(Test):
tag
=
tag
,
job
=
job
,
runner_queue
=
runner_queue
)
def
action
(
self
):
def
runTest
(
self
):
e_msg
=
(
'Test %s could not be found in the test dir %s '
'(or test path does not exist)'
%
(
self
.
name
,
data_dir
.
get_test_dir
()))
...
...
@@ -606,7 +607,7 @@ class BuggyTest(Test):
tag
=
tag
,
job
=
job
,
runner_queue
=
runner_queue
)
def
action
(
self
):
def
runTest
(
self
):
# pylint: disable=E0702
raise
self
.
params
.
get
(
'exception'
)
...
...
@@ -627,7 +628,7 @@ class NotATest(Test):
tag
=
tag
,
job
=
job
,
runner_queue
=
runner_queue
)
def
action
(
self
):
def
runTest
(
self
):
e_msg
=
(
'File %s is not executable and does not contain an avocado '
'test class in it '
%
self
.
name
)
raise
exceptions
.
NotATestError
(
e_msg
)
docs/source/DebuggingWithGDB.rst
浏览文件 @
d886f55b
...
...
@@ -21,7 +21,7 @@ Example
Take a look at ``examples/tests/modify_variable.py`` test::
def
action
(self):
def
runTest
(self):
"""
Execute 'print_variable'.
"""
...
...
@@ -102,7 +102,7 @@ test::
class HelloOutputTest(test.Test):
def
action
(self):
def
runTest
(self):
result = process.run("/path/to/hello", ignore_status=True)
self.assertIn("hello\n", result.stdout)
...
...
docs/source/WritingTests.rst
浏览文件 @
d886f55b
...
...
@@ -28,7 +28,7 @@ Now that we covered how avocado resolves tests, let's get to business.
This section is concerned with writing an avocado test. The process is not
hard, all you need to do is to create a test module, which is a python file
with a class that inherits from :class:`avocado.test.Test`. This class only
really needs to implement a method called `
action
`, which represents the actual
really needs to implement a method called `
runTest
`, which represents the actual
sequence of test operations.
Simple example
...
...
@@ -53,7 +53,7 @@ nothing but ``time.sleep([number-seconds])``::
"""
default_params = {'sleep_length': 1.0}
def
action
(self):
def
runTest
(self):
"""
Sleep for length seconds.
"""
...
...
@@ -92,7 +92,7 @@ encoded it first (base64 is the obvious choice).
Building on the previously demonstrated sleeptest, suppose that you want to save the
sleep length to be used by some other script or data analysis tool::
def
action
(self):
def
runTest
(self):
"""
Sleep for length seconds.
"""
...
...
@@ -189,7 +189,7 @@ Since avocado tests inherit from :class:`unittest.TestCase`, you can use all
the :func:`assert` class methods on your tests. Some silly examples::
class RandomExamples(test.Test):
def
action
(self):
def
runTest
(self):
self.log.debug("Verifying some random math...")
four = 2 * 2
four_ = 2 + 2
...
...
@@ -242,7 +242,7 @@ Setup and cleanup methods
=========================
If you need to perform setup actions before/after your test, you may do so
in the ``set
up`` and ``cleanup
`` methods, respectively. We'll give examples
in the ``set
Up`` and ``tearDown
`` methods, respectively. We'll give examples
in the following section.
Running third party test suites
...
...
@@ -275,7 +275,7 @@ an example that does that::
'sync_length': 100,
'sync_loop': 10}
def set
u
p(self):
def set
U
p(self):
"""
Set default params and build the synctest suite.
"""
...
...
@@ -286,7 +286,7 @@ an example that does that::
self.srcdir = os.path.join(self.srcdir, 'synctest')
build.make(self.srcdir)
def
action
(self):
def
runTest
(self):
"""
Execute synctest with the appropriate params.
"""
...
...
@@ -488,7 +488,7 @@ You may log something into the test logs using the methods in
class output_test(test.Test):
def
action
(self):
def
runTest
(self):
self.log.info('This goes to the log and it is only informational')
self.log.warn('Oh, something unexpected, non-critical happened, '
'but we can continue.')
...
...
@@ -505,7 +505,7 @@ stderr streams, you can do something like::
class output_test(test.Test):
def
action
(self):
def
runTest
(self):
self.log.info('This goes to the log and it is only informational')
self.stdout_log.info('This goes to the test stdout (will be recorded)')
self.stderr_log.info('This goes to the test stderr (will be recorded)')
...
...
@@ -618,7 +618,7 @@ a timeout of 3 seconds before avocado ends the test forcefully by sending a
default_params = {'timeout': 3.0,
'sleep_time': 5.0}
def
action
(self):
def
runTest
(self):
"""
This should throw a TestTimeoutError.
"""
...
...
examples/tests/abort.py
浏览文件 @
d886f55b
...
...
@@ -13,7 +13,7 @@ class AbortTest(test.Test):
"""
default_params
=
{
'timeout'
:
2.0
}
def
action
(
self
):
def
runTest
(
self
):
os
.
abort
()
...
...
examples/tests/cabort.py
浏览文件 @
d886f55b
...
...
@@ -17,7 +17,7 @@ class CAbort(test.Test):
default_params
=
{
'source'
:
'abort.c'
}
def
set
u
p
(
self
):
def
set
U
p
(
self
):
"""
Build 'abort'.
"""
...
...
@@ -29,7 +29,7 @@ class CAbort(test.Test):
env
=
{
'CFLAGS'
:
'-g -O0'
},
extra_args
=
'abort'
)
def
action
(
self
):
def
runTest
(
self
):
"""
Execute 'abort'.
"""
...
...
examples/tests/datadir.py
浏览文件 @
d886f55b
...
...
@@ -17,7 +17,7 @@ class DataDirTest(test.Test):
default_params
=
{
'source'
:
'datadir.c'
}
def
set
u
p
(
self
):
def
set
U
p
(
self
):
"""
Build 'datadir'.
"""
...
...
@@ -29,7 +29,7 @@ class DataDirTest(test.Test):
env
=
{
'CFLAGS'
:
'-g -O0'
},
extra_args
=
'datadir'
)
def
action
(
self
):
def
runTest
(
self
):
"""
Execute 'datadir'.
"""
...
...
examples/tests/doublefail.py
浏览文件 @
d886f55b
...
...
@@ -11,17 +11,17 @@ class DoubleFail(test.Test):
Functional test for avocado. Straight up fail the test.
"""
def
action
(
self
):
def
runTest
(
self
):
"""
Should fail.
"""
raise
exceptions
.
TestFail
(
'This test is supposed to fail'
)
def
cleanup
(
self
):
def
tearDown
(
self
):
"""
Should also fail.
"""
raise
exceptions
.
TestError
(
'Failing during
cleanup
. Yay!'
)
raise
exceptions
.
TestError
(
'Failing during
tearDown
. Yay!'
)
if
__name__
==
"__main__"
:
...
...
examples/tests/doublefree.py
浏览文件 @
d886f55b
...
...
@@ -18,7 +18,7 @@ class DoubleFreeTest(test.Test):
default_params
=
{
'source'
:
'doublefree.c'
}
def
set
u
p
(
self
):
def
set
U
p
(
self
):
"""
Build 'doublefree'.
"""
...
...
@@ -30,7 +30,7 @@ class DoubleFreeTest(test.Test):
env
=
{
'CFLAGS'
:
'-g -O0'
},
extra_args
=
'doublefree'
)
def
action
(
self
):
def
runTest
(
self
):
"""
Execute 'doublefree'.
"""
...
...
examples/tests/doublefree_nasty.py
浏览文件 @
d886f55b
...
...
@@ -18,7 +18,7 @@ class DoubleFreeTest(test.Test):
default_params
=
{
'source'
:
'doublefree.c'
}
__binary
=
None
# filename of the compiled program
def
set
u
p
(
self
):
def
set
U
p
(
self
):
"""
Build 'doublefree'.
"""
...
...
@@ -29,7 +29,7 @@ class DoubleFreeTest(test.Test):
env
=
{
'CFLAGS'
:
'-g -O0'
},
extra_args
=
self
.
__binary
)
def
action
(
self
):
def
runTest
(
self
):
"""
Execute 'doublefree'.
"""
...
...
examples/tests/errortest.py
浏览文件 @
d886f55b
...
...
@@ -11,7 +11,7 @@ class ErrorTest(test.Test):
Functional test for avocado. Throw a TestError.
"""
def
action
(
self
):
def
runTest
(
self
):
"""
This should throw a TestError.
"""
...
...
examples/tests/failtest.py
浏览文件 @
d886f55b
...
...
@@ -11,7 +11,7 @@ class FailTest(test.Test):
Functional test for avocado. Straight up fail the test.
"""
def
action
(
self
):
def
runTest
(
self
):
"""
Should fail.
"""
...
...
examples/tests/failtest_nasty.py
浏览文件 @
d886f55b
...
...
@@ -21,7 +21,7 @@ class FailTest(test.Test):
Very nasty exception test
"""
def
action
(
self
):
def
runTest
(
self
):
"""
Should fail not-that-badly
"""
...
...
examples/tests/failtest_nasty2.py
浏览文件 @
d886f55b
...
...
@@ -21,7 +21,7 @@ class FailTest(test.Test):
Very nasty exception test
"""
def
action
(
self
):
def
runTest
(
self
):
"""
Should fail.
"""
...
...
examples/tests/fiotest.py
浏览文件 @
d886f55b
...
...
@@ -21,7 +21,7 @@ class FioTest(test.Test):
default_params
=
{
'fio_tarball'
:
'fio-2.1.10.tar.bz2'
,
'fio_job'
:
'fio-mixed.job'
}
def
set
u
p
(
self
):
def
set
U
p
(
self
):
"""
Build 'fio'.
"""
...
...
@@ -31,7 +31,7 @@ class FioTest(test.Test):
self
.
srcdir
=
os
.
path
.
join
(
self
.
srcdir
,
fio_version
)
build
.
make
(
self
.
srcdir
)
def
action
(
self
):
def
runTest
(
self
):
"""
Execute 'fio' with appropriate parameters.
"""
...
...
examples/tests/gdbtest.py
浏览文件 @
d886f55b
...
...
@@ -26,7 +26,7 @@ class GdbTest(test.Test):
"-find-me-the-bug"
,
"-auto-debug-it"
]
def
set
u
p
(
self
):
def
set
U
p
(
self
):
self
.
return99_binary_path
=
os
.
path
.
join
(
self
.
outputdir
,
'return99'
)
return99_source_path
=
self
.
get_data_path
(
'return99.c'
)
process
.
system
(
'gcc -O0 -g %s -o %s'
%
(
return99_source_path
,
...
...
@@ -407,32 +407,6 @@ class GdbTest(test.Test):
r
.
cmd
(
"qfThreadInfo"
)
s
.
exit
()
def
action
(
self
):
"""
Execute tests
"""
self
.
test_start_exit
()
self
.
test_existing_commands_raw
()
self
.
test_existing_commands
()
self
.
test_load_set_breakpoint_run_exit_raw
()
self
.
test_load_set_breakpoint_run_exit
()
self
.
test_generate_core
()
self
.
test_set_multiple_break
()
self
.
test_disconnect_raw
()
self
.
test_disconnect
()
self
.
test_remote_exec
()
self
.
test_stream_messages
()
self
.
test_connect_multiple_clients
()
self
.
test_server_exit
()
self
.
test_multiple_servers
()
self
.
test_interactive
()
self
.
test_interactive_args
()
self
.
test_exit_status
()
self
.
test_server_stderr
()
self
.
test_server_stderr_redirected
()
self
.
test_server_stdout
()
self
.
test_interactive_stdout
()
self
.
test_remote
()
if
__name__
==
'__main__'
:
job
.
main
()
examples/tests/gendata.py
浏览文件 @
d886f55b
...
...
@@ -41,7 +41,7 @@ class GenDataTest(test.Test):
"outputdir"
:
self
.
outputdir
}
json
.
dump
(
output
,
open
(
output_path
,
"w"
))
def
action
(
self
):
def
runTest
(
self
):
self
.
generate_bsod
()
self
.
generate_json
()
...
...
examples/tests/linuxbuild.py
浏览文件 @
d886f55b
...
...
@@ -13,7 +13,7 @@ class LinuxBuildTest(test.Test):
default_params
=
{
'linux_version'
:
'3.14.5'
,
'linux_config'
:
'config'
}
def
set
u
p
(
self
):
def
set
U
p
(
self
):
kernel_version
=
self
.
params
.
linux_version
config_path
=
self
.
get_data_path
(
'config'
)
self
.
linux_build
=
kernel_build
.
KernelBuild
(
kernel_version
,
...
...
@@ -23,7 +23,7 @@ class LinuxBuildTest(test.Test):
self
.
linux_build
.
uncompress
()
self
.
linux_build
.
configure
()
def
action
(
self
):
def
runTest
(
self
):
self
.
linux_build
.
build
()
...
...
examples/tests/modify_variable.py
浏览文件 @
d886f55b
...
...
@@ -21,7 +21,7 @@ class PrintVariableTest(test.Test):
default_params
=
{
'source'
:
'print_variable.c'
}
__binary
=
None
# filename of the compiled program
def
set
u
p
(
self
):
def
set
U
p
(
self
):
"""
Build 'print_variable'.
"""
...
...
@@ -32,7 +32,7 @@ class PrintVariableTest(test.Test):
env
=
{
'CFLAGS'
:
'-g -O0'
},
extra_args
=
self
.
__binary
)
def
action
(
self
):
def
runTest
(
self
):
"""
Execute 'print_variable'.
"""
...
...
examples/tests/multiplextest.py
浏览文件 @
d886f55b
...
...
@@ -22,7 +22,7 @@ class MultiplexTest(test.Test):
'ping_timeout'
:
10
,
'ping_tries'
:
5
}
def
set
u
p
(
self
):
def
set
U
p
(
self
):
self
.
compile_code
()
self
.
set_hugepages
()
self
.
set_numa_balance
()
...
...
@@ -57,7 +57,7 @@ class MultiplexTest(test.Test):
if
self
.
params
.
enable_msx_vectors
==
'yes'
:
self
.
log
.
info
(
'Enabling msx vectors'
)
def
action
(
self
):
def
runTest
(
self
):
self
.
log
.
info
(
'Executing synctest...'
)
self
.
log
.
info
(
'synctest --timeout %s --tries %s'
,
self
.
params
.
sync_timeout
,
...
...
examples/tests/passtest.py
浏览文件 @
d886f55b
...
...
@@ -10,7 +10,7 @@ class PassTest(test.Test):
Example test that passes.
"""
def
action
(
self
):
def
runTest
(
self
):
"""
A test simply doesn't have to fail in order to pass
"""
...
...
examples/tests/raise.py
浏览文件 @
d886f55b
...
...
@@ -18,7 +18,7 @@ class Raise(test.Test):
default_params
=
{
'source'
:
'raise.c'
,
'signal_number'
:
15
}
def
set
u
p
(
self
):
def
set
U
p
(
self
):
"""
Build 'raise'.
"""
...
...
@@ -30,7 +30,7 @@ class Raise(test.Test):
env
=
{
'CFLAGS'
:
'-g -O0'
},
extra_args
=
'raise'
)
def
action
(
self
):
def
runTest
(
self
):
"""
Execute 'raise'.
"""
...
...
examples/tests/skiptest.py
浏览文件 @
d886f55b
...
...
@@ -11,7 +11,7 @@ class SkipTest(test.Test):
Functional test for avocado. Throw a TestNAError (skips the test).
"""
def
action
(
self
):
def
runTest
(
self
):
"""
This should throw a TestNAError (skips the test).
"""
...
...
examples/tests/sleeptenmin.py
浏览文件 @
d886f55b
...
...
@@ -16,7 +16,7 @@ class SleepTenMin(test.Test):
'sleep_cycles'
:
1
,
'sleep_method'
:
'builtin'
}
def
action
(
self
):
def
runTest
(
self
):
"""
Sleep for length seconds.
"""
...
...
examples/tests/sleeptest.py
浏览文件 @
d886f55b
...
...
@@ -13,7 +13,7 @@ class SleepTest(test.Test):
"""
default_params
=
{
'sleep_length'
:
1.0
}
def
action
(
self
):
def
runTest
(
self
):
"""
Sleep for length seconds.
"""
...
...
examples/tests/synctest.py
浏览文件 @
d886f55b
...
...
@@ -19,7 +19,7 @@ class SyncTest(test.Test):
'sync_loop'
:
10
,
'debug_symbols'
:
True
}
def
set
u
p
(
self
):
def
set
U
p
(
self
):
"""
Build the synctest suite.
"""
...
...
@@ -34,7 +34,7 @@ class SyncTest(test.Test):
else
:
build
.
make
(
self
.
srcdir
)
def
action
(
self
):
def
runTest
(
self
):
"""
Execute synctest with the appropriate params.
"""
...
...
examples/tests/timeouttest.py
浏览文件 @
d886f55b
...
...
@@ -14,7 +14,7 @@ class TimeoutTest(test.Test):
default_params
=
{
'timeout'
:
3.0
,
'sleep_time'
:
5.0
}
def
action
(
self
):
def
runTest
(
self
):
"""
This should throw a TestTimeoutError.
"""
...
...
examples/tests/trinity.py
浏览文件 @
d886f55b
...
...
@@ -27,7 +27,7 @@ class TrinityTest(test.Test):
'victims_path'
:
None
,
'stress'
:
None
}
def
set
u
p
(
self
):
def
set
U
p
(
self
):
"""
Build trinity.
"""
...
...
@@ -39,7 +39,7 @@ class TrinityTest(test.Test):
build
.
make
(
self
.
srcdir
)
self
.
victims_path
=
data_factory
.
make_dir_and_populate
(
self
.
workdir
)
def
action
(
self
):
def
runTest
(
self
):
"""
Execute the trinity syscall fuzzer with the appropriate params.
"""
...
...
examples/tests/warntest.py
浏览文件 @
d886f55b
...
...
@@ -11,7 +11,7 @@ class WarnTest(test.Test):
Functional test for avocado. Throw a TestWarn.
"""
def
action
(
self
):
def
runTest
(
self
):
"""
This should throw a TestWarn.
"""
...
...
examples/tests/whiteboard.py
浏览文件 @
d886f55b
...
...
@@ -16,7 +16,7 @@ class WhiteBoard(test.Test):
'whiteboard_data_size'
:
'10'
,
'whiteboard_writes'
:
'1'
}
def
action
(
self
):
def
runTest
(
self
):
if
self
.
params
.
whiteboard_data_file
:
self
.
log
.
info
(
'Writing data to whiteboard from file: %s'
,
self
.
params
.
whiteboard_data_file
)
...
...
selftests/all/functional/avocado/basic_tests.py
浏览文件 @
d886f55b
...
...
@@ -104,7 +104,7 @@ class RunnerOperationTest(unittest.TestCase):
"Avocado crashed (rc %d):
\n
%s"
%
(
unexpected_rc
,
result
))
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
"Avocado did not return rc %d:
\n
%s"
%
(
expected_rc
,
result
))
self
.
assertIn
(
"TestError: Failing during
cleanup
. Yay!"
,
output
,
self
.
assertIn
(
"TestError: Failing during
tearDown
. Yay!"
,
output
,
"Cleanup exception not printed to log output"
)
self
.
assertIn
(
"TestFail: This test is supposed to fail"
,
output
,
...
...
selftests/all/functional/avocado/loader_tests.py
浏览文件 @
d886f55b
...
...
@@ -20,7 +20,7 @@ from avocado import job
from avocado import test
class PassTest(test.Test):
def
action
(self):
def
runTest
(self):
pass
if __name__ == "__main__":
...
...
@@ -33,7 +33,7 @@ from avocado import test
import adsh
class PassTest(test.Test):
def
action
(self):
def
runTest
(self):
pass
if __name__ == "__main__":
...
...
selftests/all/unit/avocado/loader_unittest.py
100755 → 100644
浏览文件 @
d886f55b
...
...
@@ -22,7 +22,7 @@ from avocado import job
from avocado import test
class PassTest(test.Test):
def
action
(self):
def
runTest
(self):
pass
if __name__ == "__main__":
...
...
@@ -35,7 +35,7 @@ from avocado import test
import adsh
class PassTest(test.Test):
def
action
(self):
def
runTest
(self):
pass
if __name__ == "__main__":
...
...
@@ -71,6 +71,17 @@ class MyInheritedTest(MyBaseTest):
pass
"""
AVOCADO_MULTIPLE_TESTS
=
"""from avocado import test
class MultipleMethods(test.Test):
def test_one(self):
pass
def testTwo(self):
pass
def foo(self):
pass
"""
class
_DebugJob
(
object
):
logdir
=
tempfile
.
mkdtemp
()
...
...
@@ -88,10 +99,10 @@ class LoaderTest(unittest.TestCase):
'avocado_loader_unittest'
)
simple_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
simple_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
simple_test
.
path
})[
0
]
)
self
.
assertTrue
(
test_class
==
test
.
SimpleTest
,
test_class
)
tc
=
test_class
(
**
test_parameters
)
tc
.
action
()
tc
.
runTest
()
simple_test
.
remove
()
def
test_load_simple_not_exec
(
self
):
...
...
@@ -100,10 +111,10 @@ class LoaderTest(unittest.TestCase):
mode
=
0664
)
simple_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
simple_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
simple_test
.
path
})[
0
]
)
self
.
assertTrue
(
test_class
==
test
.
NotATest
,
test_class
)
tc
=
test_class
(
**
test_parameters
)
self
.
assertRaises
(
exceptions
.
NotATestError
,
tc
.
action
)
self
.
assertRaises
(
exceptions
.
NotATestError
,
tc
.
runTest
)
simple_test
.
remove
()
def
test_load_pass
(
self
):
...
...
@@ -112,12 +123,12 @@ class LoaderTest(unittest.TestCase):
'avocado_loader_unittest'
)
avocado_pass_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
avocado_pass_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
avocado_pass_test
.
path
})[
0
]
)
self
.
assertTrue
(
str
(
test_class
)
==
"<class 'passtest.PassTest'>"
,
str
(
test_class
))
self
.
assertTrue
(
issubclass
(
test_class
,
test
.
Test
))
tc
=
test_class
(
**
test_parameters
)
tc
.
action
()
tc
.
runTest
()
avocado_pass_test
.
remove
()
def
test_load_inherited
(
self
):
...
...
@@ -126,7 +137,7 @@ class LoaderTest(unittest.TestCase):
'avocado_loader_unittest'
)
avocado_base_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
avocado_base_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
avocado_base_test
.
path
})[
0
]
)
self
.
assertTrue
(
str
(
test_class
)
==
"<class 'base.MyBaseTest'>"
,
str
(
test_class
))
...
...
@@ -135,7 +146,7 @@ class LoaderTest(unittest.TestCase):
'avocado_loader_unittest'
)
avocado_inherited_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
avocado_inherited_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
avocado_inherited_test
.
path
})[
0
]
)
self
.
assertTrue
(
str
(
test_class
)
==
"<class 'inherited.MyInheritedTest'>"
,
str
(
test_class
))
avocado_base_test
.
remove
()
...
...
@@ -147,10 +158,10 @@ class LoaderTest(unittest.TestCase):
'avocado_loader_unittest'
)
avocado_buggy_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
avocado_buggy_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
avocado_buggy_test
.
path
})[
0
]
)
self
.
assertTrue
(
test_class
==
test
.
SimpleTest
,
test_class
)
tc
=
test_class
(
**
test_parameters
)
self
.
assertRaises
(
exceptions
.
TestFail
,
tc
.
action
)
self
.
assertRaises
(
exceptions
.
TestFail
,
tc
.
runTest
)
avocado_buggy_test
.
remove
()
def
test_load_buggy_not_exec
(
self
):
...
...
@@ -160,10 +171,10 @@ class LoaderTest(unittest.TestCase):
mode
=
0664
)
avocado_buggy_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
avocado_buggy_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
avocado_buggy_test
.
path
})[
0
]
)
self
.
assertTrue
(
test_class
==
test
.
BuggyTest
,
test_class
)
tc
=
test_class
(
**
test_parameters
)
self
.
assertRaises
(
ImportError
,
tc
.
action
)
self
.
assertRaises
(
ImportError
,
tc
.
runTest
)
avocado_buggy_test
.
remove
()
def
test_load_not_a_test
(
self
):
...
...
@@ -173,10 +184,10 @@ class LoaderTest(unittest.TestCase):
mode
=
0664
)
avocado_not_a_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
avocado_not_a_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
avocado_not_a_test
.
path
})[
0
]
)
self
.
assertTrue
(
test_class
==
test
.
NotATest
,
test_class
)
tc
=
test_class
(
**
test_parameters
)
self
.
assertRaises
(
exceptions
.
NotATestError
,
tc
.
action
)
self
.
assertRaises
(
exceptions
.
NotATestError
,
tc
.
runTest
)
avocado_not_a_test
.
remove
()
def
test_load_not_a_test_exec
(
self
):
...
...
@@ -184,12 +195,12 @@ class LoaderTest(unittest.TestCase):
'avocado_loader_unittest'
)
avocado_not_a_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
avocado_not_a_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
avocado_not_a_test
.
path
})[
0
]
)
self
.
assertTrue
(
test_class
==
test
.
SimpleTest
,
test_class
)
tc
=
test_class
(
**
test_parameters
)
# The test can't be executed (no shebang), raising an OSError
# (OSError: [Errno 8] Exec format error)
self
.
assertRaises
(
OSError
,
tc
.
action
)
self
.
assertRaises
(
OSError
,
tc
.
runTest
)
avocado_not_a_test
.
remove
()
def
test_py_simple_test
(
self
):
...
...
@@ -198,10 +209,10 @@ class LoaderTest(unittest.TestCase):
'avocado_loader_unittest'
)
avocado_simple_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
avocado_simple_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
avocado_simple_test
.
path
})[
0
]
)
self
.
assertTrue
(
test_class
==
test
.
SimpleTest
)
tc
=
test_class
(
**
test_parameters
)
tc
.
action
()
tc
.
runTest
()
avocado_simple_test
.
remove
()
def
test_py_simple_test_notexec
(
self
):
...
...
@@ -211,12 +222,22 @@ class LoaderTest(unittest.TestCase):
mode
=
0664
)
avocado_simple_test
.
save
()
test_class
,
test_parameters
=
(
self
.
loader
.
discover_test
(
params
=
{
'id'
:
avocado_simple_test
.
path
})
)
self
.
loader
.
discover_test
s
(
params
=
{
'id'
:
avocado_simple_test
.
path
})[
0
]
)
self
.
assertTrue
(
test_class
==
test
.
NotATest
)
tc
=
test_class
(
**
test_parameters
)
self
.
assertRaises
(
exceptions
.
NotATestError
,
tc
.
action
)
self
.
assertRaises
(
exceptions
.
NotATestError
,
tc
.
runTest
)
avocado_simple_test
.
remove
()
def
test_multiple_methods
(
self
):
avocado_multiple_tests
=
script
.
TemporaryScript
(
'multipletests.py'
,
AVOCADO_MULTIPLE_TESTS
,
'avocado_multiple_tests_unittest'
,
mode
=
0664
)
avocado_multiple_tests
.
save
()
suite
=
self
.
loader
.
discover_tests
(
params
=
{
'id'
:
avocado_multiple_tests
.
path
})
self
.
assertEqual
(
len
(
suite
),
2
)
avocado_multiple_tests
.
remove
()
def
tearDown
(
self
):
if
os
.
path
.
isdir
(
self
.
job
.
logdir
):
shutil
.
rmtree
(
self
.
job
.
logdir
)
...
...
selftests/all/unit/avocado/multiples_tests.py
0 → 100644
浏览文件 @
d886f55b
#!/usr/bin/python
from
avocado
import
test
from
avocado
import
job
class
MultipleTests
(
test
.
Test
):
"""
Following the idea of unittest module,
every test method starts with a 'test' prefix,
so that 'test_foo' and 'testFoo' are test methods,
but 'division_by_zero' and 'action' are not.
"""
def
setUp
(
self
):
self
.
hello
=
"Hi there!"
def
test_hello
(
self
):
self
.
assertEqual
(
self
.
hello
,
"Hi there!"
)
def
testIdentity
(
self
):
self
.
assertTrue
(
1
,
1
)
def
division_by_zero
(
self
):
"This method should never execute"
return
1
/
0
def
action
(
self
):
"This method should never execute"
pass
if
__name__
==
'__main__'
:
job
.
main
()
selftests/all/unit/avocado/test_unittest.py
浏览文件 @
d886f55b
...
...
@@ -21,17 +21,17 @@ from avocado.utils import script
@
unittest
.
skip
(
"This class should not be tested per se"
)
class
AvocadoPass
(
test
.
Test
):
def
action
(
self
):
def
runTest
(
self
):
variable
=
True
self
.
assertTrue
(
variable
)
self
.
whiteboard
=
'foo'
@
unittest
.
skip
(
"This class should not be tested per se"
)
class
AvocadoFailNoAction
(
test
.
Test
):
class
EmptyTest
(
test
.
Test
):
"""
I don't have
an action() method
defined!
I don't have
runTest()
defined!
"""
pass
...
...
@@ -51,19 +51,14 @@ class TestClassTest(unittest.TestCase):
self
.
tst_instance_pass
=
AvocadoPass
(
base_logdir
=
self
.
base_logdir
)
self
.
tst_instance_pass
.
run_avocado
()
def
testFailNoActionRunTest
(
self
):
tst_instance
=
AvocadoFailNoAction
()
try
:
tst_instance
.
action
()
raise
AssertionError
(
"Test instance did not raise NotImplementedError"
)
except
NotImplementedError
:
pass
def
testFailNoActionRunAvocado
(
self
):
tst_instance
=
AvocadoFailNoAction
()
tst_instance
.
run_avocado
()
self
.
assertEqual
(
tst_instance
.
status
,
'FAIL'
)
self
.
assertEqual
(
tst_instance
.
fail_class
,
'NotImplementedError'
)
def
testRunTest
(
self
):
tst
=
EmptyTest
()
self
.
assertEqual
(
tst
.
runTest
(),
None
)
def
testRunAvocado
(
self
):
tst
=
EmptyTest
()
tst
.
run_avocado
()
self
.
assertEqual
(
tst
.
status
,
'PASS'
)
def
testClassAttributesName
(
self
):
self
.
assertEqual
(
self
.
tst_instance_pass
.
name
,
'AvocadoPass'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录