Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
b5b914c0
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,发现更多精彩内容 >>
提交
b5b914c0
编写于
8月 24, 2014
作者:
L
Lucas Meneghel Rodrigues
提交者:
Lucas Meneghel Rodrigues
8月 24, 2014
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #161 from ruda/refactory_plugins
Refactory plugins
上级
c01b50ec
2cb03fd5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
158 addition
and
24 deletion
+158
-24
avocado/plugins/lister.py
avocado/plugins/lister.py
+2
-1
avocado/plugins/manager.py
avocado/plugins/manager.py
+11
-3
avocado/plugins/plugin.py
avocado/plugins/plugin.py
+19
-6
selftests/all/functional/avocado/basic_tests.py
selftests/all/functional/avocado/basic_tests.py
+42
-14
selftests/all/unit/avocado/plugins_unittest.py
selftests/all/unit/avocado/plugins_unittest.py
+84
-0
未找到文件。
avocado/plugins/lister.py
浏览文件 @
b5b914c0
...
...
@@ -50,5 +50,6 @@ class PluginsList(plugin.Plugin):
status
=
bcolors
.
healthy_str
(
"Enabled"
)
else
:
status
=
bcolors
.
fail_header_str
(
"Disabled"
)
pipe
.
write
(
format_str
%
(
bcolors
.
header_str
(
plug
.
name
),
plug
.
__doc__
.
strip
(),
pipe
.
write
(
format_str
%
(
bcolors
.
header_str
(
plug
.
name
),
plug
.
description
,
status
))
avocado/plugins/manager.py
浏览文件 @
b5b914c0
...
...
@@ -91,18 +91,26 @@ class ExternalPluginManager(PluginManager):
import
imp
if
path
:
candidates
=
glob
(
os
.
path
.
join
(
path
,
pattern
))
candidates
=
[(
os
.
path
.
splitext
(
os
.
path
.
basename
(
x
))[
0
],
path
)
for
x
in
candidates
]
candidates
=
[(
x
[
0
],
imp
.
find_module
(
x
[
0
],
[
path
]))
for
x
in
candidates
]
candidates
=
[(
os
.
path
.
splitext
(
os
.
path
.
basename
(
x
))[
0
],
path
)
for
x
in
candidates
]
candidates
=
[(
x
[
0
],
imp
.
find_module
(
x
[
0
],
[
path
]))
for
x
in
candidates
]
for
candidate
in
candidates
:
try
:
mod
=
imp
.
load_module
(
candidate
[
0
],
*
candidate
[
1
])
except
Exception
as
err
:
log
.
error
(
"Could not load plugin '%s': %s"
,
candidate
[
0
],
err
)
log
.
error
(
"Could not load module plugin '%s': %s"
,
candidate
[
0
],
err
)
else
:
any_plugin
=
False
for
name
in
mod
.
__dict__
:
x
=
getattr
(
mod
,
name
)
if
isinstance
(
x
,
type
)
and
issubclass
(
x
,
Plugin
):
self
.
add_plugin
(
x
())
any_plugin
=
True
if
not
any_plugin
:
log
.
error
(
"Could not find any plugin in module '%s'"
,
candidate
[
0
])
def
add_plugins
(
self
,
plugins
):
for
plugin
in
plugins
:
...
...
avocado/plugins/plugin.py
浏览文件 @
b5b914c0
...
...
@@ -23,15 +23,28 @@ class Plugin(object):
You'll inherit from this to write you own plugins.
"""
name
=
'
plugin
'
enabled
=
Tru
e
name
=
'
noname
'
enabled
=
Fals
e
def
__init__
(
self
):
"""Creates a new plugin instance."""
self
.
name
=
self
.
__class__
.
name
self
.
enabled
=
self
.
__class__
.
enabled
def
__init__
(
self
,
name
=
None
,
enabled
=
None
):
"""Creates a new plugin instance.
:param name: plugin short name.
:param enabled: plugin status: enabled or not.
"""
if
name
is
not
None
:
self
.
name
=
name
if
enabled
is
not
None
:
self
.
enabled
=
enabled
if
self
.
__doc__
is
not
None
:
self
.
description
=
self
.
__doc__
.
strip
()
else
:
self
.
description
=
'There is no description for this plugin'
self
.
configured
=
False
def
__repr__
(
self
):
return
"%s(name='%s')"
%
(
self
.
__class__
.
__name__
,
self
.
name
)
def
configure
(
self
,
app_parser
,
cmd_parser
):
"""Configuration and argument parsing.
...
...
selftests/all/functional/avocado/basic_tests.py
浏览文件 @
b5b914c0
...
...
@@ -50,6 +50,19 @@ from avocado.plugins.plugin import Plugin
class VoidPlugin(Plugin)
"""
HELLO_PLUGIN_CONTENTS
=
"""#!/usr/bin/env python
from avocado.plugins.plugin import Plugin
class HelloWorld(Plugin):
name = 'hello'
enabled = True
def configure(self, app_parser, cmd_parser):
parser = cmd_parser.add_parser('hello')
parser.set_defaults(func=self.hello)
self.configured = True
def hello(self, args):
print 'Hello World!'
"""
class
RunnerOperationTest
(
unittest
.
TestCase
):
...
...
@@ -247,33 +260,54 @@ class RunnerDropinTest(unittest.TestCase):
shutil
.
rmtree
(
self
.
base_logdir
,
ignore_errors
=
True
)
class
PluginsTest
(
unittest
.
TestCase
):
class
External
PluginsTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
base_outputdir
=
tempfile
.
mkdtemp
(
prefix
=
'avocado_plugins'
)
self
.
base_sourcedir
=
tempfile
.
mkdtemp
(
prefix
=
'avocado_source_plugins'
)
def
test_void_plugin
(
self
):
self
.
void_plugin
=
os
.
path
.
join
(
self
.
base_sourcedir
,
'avocado_void.py'
)
with
open
(
self
.
void_plugin
,
'w'
)
as
void
:
void
.
write
(
VOID_PLUGIN_CONTENTS
)
os
.
chmod
(
self
.
void_plugin
,
0775
)
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado --plugins %s plugins'
%
self
.
base_sourcedir
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_output
=
'noname'
self
.
assertIn
(
expected_output
,
result
.
stdout
)
def
test_syntax_error_plugin
(
self
):
self
.
syntax_err_plugin
=
os
.
path
.
join
(
self
.
base_sourcedir
,
'avocado_syntax_err.py'
)
with
open
(
self
.
syntax_err_plugin
,
'w'
)
as
synerr
:
synerr
.
write
(
SYNTAX_ERROR_PLUGIN_CONTENTS
)
os
.
chmod
(
self
.
syntax_err_plugin
,
0775
)
def
test_void_plugin
(
self
):
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado --plugins %s'
%
self
.
base_sourcedir
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_output
=
'
Plugins must implement the method configure
'
expected_output
=
'
invalid syntax
'
self
.
assertIn
(
expected_output
,
result
.
stderr
)
def
test_syntax_error_plugin
(
self
):
def
test_hello_plugin
(
self
):
self
.
hello_plugin
=
os
.
path
.
join
(
self
.
base_sourcedir
,
'avocado_hello.py'
)
with
open
(
self
.
hello_plugin
,
'w'
)
as
hello
:
hello
.
write
(
HELLO_PLUGIN_CONTENTS
)
os
.
chmod
(
self
.
hello_plugin
,
0775
)
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado --plugins %s'
%
self
.
base_sourcedir
cmd_line
=
'./scripts/avocado --plugins %s
hello
'
%
self
.
base_sourcedir
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_output
=
'invalid syntax'
self
.
assertIn
(
expected_output
,
result
.
stderr
)
expected_output
=
'Hello World!'
self
.
assertIn
(
expected_output
,
result
.
stdout
)
def
tearDown
(
self
):
if
os
.
path
.
isdir
(
self
.
base_sourcedir
):
shutil
.
rmtree
(
self
.
base_sourcedir
,
ignore_errors
=
True
)
class
PluginsTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
base_outputdir
=
tempfile
.
mkdtemp
(
prefix
=
'avocado_plugins'
)
def
test_sysinfo_plugin
(
self
):
os
.
chdir
(
basedir
)
...
...
@@ -319,12 +353,6 @@ class PluginsTest(unittest.TestCase):
(
expected_rc
,
result
))
self
.
assertNotIn
(
'Disabled'
,
output
)
def
tearDown
(
self
):
if
os
.
path
.
isdir
(
self
.
base_outputdir
):
shutil
.
rmtree
(
self
.
base_outputdir
,
ignore_errors
=
True
)
if
os
.
path
.
isdir
(
self
.
base_sourcedir
):
shutil
.
rmtree
(
self
.
base_sourcedir
,
ignore_errors
=
True
)
class
ParseXMLError
(
Exception
):
pass
...
...
selftests/all/unit/avocado/plugins_unittest.py
0 → 100755
浏览文件 @
b5b914c0
#!/usr/bin/env python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2014
# Author: Ruda Moura <rmoura@redhat.com>
import
sys
import
os
import
unittest
# simple magic for using scripts within a source tree
basedir
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
basedir
=
os
.
path
.
dirname
(
basedir
)
if
os
.
path
.
isdir
(
os
.
path
.
join
(
basedir
,
'avocado'
)):
sys
.
path
.
append
(
basedir
)
from
avocado.plugins
import
plugin
class
NullPlugin
(
plugin
.
Plugin
):
pass
class
FakePlugin
(
plugin
.
Plugin
):
"""
Fake plugin
"""
name
=
'fake'
enabled
=
True
def
configure
(
self
,
app_parser
,
cmd_parser
):
self
.
configured
=
True
def
activate
(
self
,
app_args
):
self
.
activated
=
True
class
PluginsBasicTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
p
=
plugin
.
Plugin
()
self
.
null
=
NullPlugin
()
self
.
fake
=
FakePlugin
()
self
.
disabled_fake
=
FakePlugin
(
enabled
=
False
)
def
testCreate
(
self
):
self
.
assertTrue
(
self
.
p
)
self
.
assertFalse
(
self
.
p
.
enabled
)
self
.
assertEqual
(
self
.
p
.
name
,
'noname'
)
self
.
assertTrue
(
self
.
p
.
description
)
self
.
assertTrue
(
self
.
null
.
name
,
'noname'
)
self
.
assertFalse
(
self
.
null
.
enabled
)
self
.
assertTrue
(
self
.
fake
)
self
.
assertEqual
(
self
.
fake
.
name
,
'fake'
)
self
.
assertTrue
(
self
.
fake
.
enabled
)
self
.
assertEqual
(
self
.
fake
.
description
,
'Fake plugin'
)
self
.
assertFalse
(
self
.
disabled_fake
.
enabled
)
def
testConfigure
(
self
):
self
.
assertRaises
(
NotImplementedError
,
self
.
p
.
configure
,
None
,
None
)
self
.
assertRaises
(
NotImplementedError
,
self
.
null
.
configure
,
None
,
None
)
self
.
fake
.
configure
(
None
,
None
)
self
.
assertTrue
(
self
.
fake
.
configured
,
True
)
def
testActivate
(
self
):
self
.
p
.
activate
(
None
)
self
.
null
.
activate
(
None
)
self
.
fake
.
activate
(
None
)
self
.
assertTrue
(
self
.
fake
.
activated
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录