提交 553cacdf 编写于 作者: R Rudá Moura 提交者: Ruda Moura

selftests: "Hello World!" external plugin, functional test.

Add new "hello world!" plugin, to perform functional tests
on external plugins.

Created class ExternalPluginsTest() to move all
functional tests regarding external plugins there.
Signed-off-by: NRuda Moura <rmoura@redhat.com>
上级 6a1311af
......@@ -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 ExternalPluginsTest(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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册