提交 41ad170d 编写于 作者: C Cleber Rosa

Multiplexer: move respective tests to the yaml_to_mux plugin

And drop the notion of a "multiplex capable" Avocado.  If the plugin is
installed, then we assume the dependencies have been fulfilled.  The plugin
presence is used then for the creation of the test suite, including the
plugin's own tests.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 e24150a4
......@@ -25,6 +25,7 @@ setup(name='avocado-framework-plugin-varianter-yaml-to-mux',
packages=find_packages(),
include_package_data=True,
install_requires=['avocado-framework', 'PyYAML'],
test_suite='tests',
entry_points={
"avocado.plugins.cli": [
"yaml_to_mux = avocado_varianter_yaml_to_mux:YamlToMuxCLI",
......
......@@ -7,20 +7,20 @@ from avocado.core import exit_codes
from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..')
basedir = os.path.abspath(basedir)
AVOCADO = os.environ.get("UNITTEST_AVOCADO_CMD", "./scripts/avocado")
DEBUG_OUT = """Variant mint-debug-amd-virtio-07c6: amd@selftests/.data/mux-environment.yaml, virtio@selftests/.data/mux-environment.yaml, mint@selftests/.data/mux-environment.yaml, debug@selftests/.data/mux-environment.yaml
/distro/mint:init => systemv@selftests/.data/mux-environment.yaml:/distro/mint
/env/debug:opt_CFLAGS => -O0 -g@selftests/.data/mux-environment.yaml:/env/debug
/hw/cpu/amd:cpu_CFLAGS => -march=athlon64@selftests/.data/mux-environment.yaml:/hw/cpu/amd
/hw/cpu/amd:joinlist => ['first_item']@selftests/.data/mux-selftest.yaml:/hw/cpu + ['second', 'third']@selftests/.data/mux-selftest.yaml:/hw/cpu/amd
/hw/disk/virtio:disk_type => virtio@selftests/.data/mux-environment.yaml:/hw/disk/virtio
/hw/disk:corruptlist => nonlist@selftests/.data/mux-selftest.yaml:/hw/disk
/hw:corruptlist => ['upper_node_list']@selftests/.data/mux-selftest.yaml:/hw
DEBUG_OUT = """
Variant mint-debug-amd-virtio-935e: amd@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, virtio@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, mint@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml, debug@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml
/distro/mint:init => systemv@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml:/distro/mint
/env/debug:opt_CFLAGS => -O0 -g@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml:/env/debug
/hw/cpu/amd:cpu_CFLAGS => -march=athlon64@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml:/hw/cpu/amd
/hw/cpu/amd:joinlist => ['first_item']@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-selftest.yaml:/hw/cpu + ['second', 'third']@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-selftest.yaml:/hw/cpu/amd
/hw/disk/virtio:disk_type => virtio@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml:/hw/disk/virtio
/hw/disk:corruptlist => nonlist@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-selftest.yaml:/hw/disk
/hw:corruptlist => ['upper_node_list']@optional_plugins/varianter_yaml_to_mux/tests/.data/mux-selftest.yaml:/hw
"""
......@@ -56,10 +56,11 @@ class MultiplexTests(unittest.TestCase):
def test_mplex_debug(self):
cmd_line = ('%s variants -c -d -m '
'/:selftests/.data/mux-selftest.yaml '
'/:selftests/.data/mux-environment.yaml '
'/:selftests/.data/mux-selftest.yaml '
'/:selftests/.data/mux-environment.yaml' % AVOCADO)
'/:optional_plugins/varianter_yaml_to_mux/tests/.data/mux-selftest.yaml '
'/:optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml '
'/:optional_plugins/varianter_yaml_to_mux/tests/.data/mux-selftest.yaml '
'/:optional_plugins/varianter_yaml_to_mux/tests/.data/mux-environment.yaml'
% AVOCADO)
expected_rc = exit_codes.AVOCADO_ALL_OK
result = self.run_and_check(cmd_line, expected_rc)
self.assertIn(DEBUG_OUT, result.stdout)
......@@ -133,9 +134,9 @@ class MultiplexTests(unittest.TestCase):
self.run_and_check(cmd_line, expected_rc, (4, 0))
def test_empty_file(self):
cmd_line = ("%s run --job-results-dir %s -m selftests/.data/empty_file"
" -- passtest.py"
% (AVOCADO, self.tmpdir))
cmd_line = ("%s run --job-results-dir %s -m optional_plugins/"
"varianter_yaml_to_mux/tests/.data/empty_file -- "
"passtest.py" % (AVOCADO, self.tmpdir))
result = self.run_and_check(cmd_line, exit_codes.AVOCADO_ALL_OK,
(1, 0))
......
......@@ -2,7 +2,6 @@ import copy
import itertools
import os
import pickle
import pkg_resources
import unittest
import yaml
......@@ -12,19 +11,9 @@ import avocado_varianter_yaml_to_mux as yaml_to_mux
from avocado_varianter_yaml_to_mux import mux
from avocado.core import tree, parameters
BASEDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
BASEDIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
BASEDIR = os.path.abspath(BASEDIR)
PATH_PREFIX = os.path.relpath(BASEDIR) + os.path.sep
def plugin_available(plugin_name):
try:
pkg_resources.require(plugin_name)
return True
except pkg_resources.DistributionNotFound:
return False
def combine(leaves_pools):
""" Joins remaining leaves and pools and create product """
......@@ -35,8 +24,9 @@ def combine(leaves_pools):
class TestMuxTree(unittest.TestCase):
# Share tree with all tests
tree = yaml_to_mux.create_from_yaml(['/:' + PATH_PREFIX +
'selftests/.data/mux-selftest.yaml'])
tree_yaml_path = os.path.join(BASEDIR, 'tests/.data/mux-selftest.yaml')
tree_yaml_url = '/:%s' % tree_yaml_path
tree = yaml_to_mux.create_from_yaml([tree_yaml_url])
def test_node_order(self):
self.assertIsInstance(self.tree, mux.MuxTreeNode)
......@@ -176,9 +166,10 @@ class TestMuxTree(unittest.TestCase):
tree2.children[0].children[2].children[1].value)
def test_advanced_yaml(self):
tree2 = yaml_to_mux.create_from_yaml(['/:' + PATH_PREFIX +
'selftests/.data/mux-selftest-advanced.'
'yaml'])
tree2_yaml_path = os.path.join(BASEDIR,
'tests/.data/mux-selftest-advanced.yaml')
tree2_yaml_url = '/:%s' % tree2_yaml_path
tree2 = yaml_to_mux.create_from_yaml([tree2_yaml_url])
exp = ['intel', 'amd', 'arm', 'scsi', 'virtio', 'fedora', '6',
'7', 'gentoo', 'mint', 'prod', 'new_node', 'on', 'dict']
act = tree2.get_leaves()
......@@ -244,12 +235,10 @@ class TestMuxTree(unittest.TestCase):
class TestMultiplex(unittest.TestCase):
@unittest.skipUnless(plugin_available("avocado-framework-plugin-varianter-yaml-to-mux"),
"Plugin avocado_varianter_yaml_to_mux not available")
def setUp(self):
self.mux_tree = yaml_to_mux.create_from_yaml(['/:' + PATH_PREFIX +
'selftests/.data/mux-selftest.'
'yaml'])
tree_yaml_path = os.path.join(BASEDIR, 'tests/.data/mux-selftest.yaml')
tree_yaml_url = '/:%s' % tree_yaml_path
self.mux_tree = yaml_to_mux.create_from_yaml([tree_yaml_url])
self.mux_full = tuple(mux.MuxTree(self.mux_tree))
def test_empty(self):
......@@ -266,24 +255,27 @@ class TestMultiplex(unittest.TestCase):
self.assertEqual(len(self.mux_full), 12)
def test_create_variants(self):
from_file = yaml_to_mux.create_from_yaml(
["/:" + PATH_PREFIX + 'selftests/.data/mux-selftest.yaml'])
tree_yaml_path = os.path.join(BASEDIR, 'tests/.data/mux-selftest.yaml')
tree_yaml_url = '/:%s' % tree_yaml_path
from_file = yaml_to_mux.create_from_yaml([tree_yaml_url])
from_file = mux.MuxTree(from_file)
self.assertEqual(self.mux_full, tuple(from_file))
# Filters are tested in tree_unittests, only verify `multiplex_yamls` calls
def test_filter_only(self):
exp = (['intel', 'scsi'], ['intel', 'virtio'])
act = yaml_to_mux.create_from_yaml(["/:" + PATH_PREFIX +
'selftests/.data/mux-selftest.yaml'])
tree_yaml_path = os.path.join(BASEDIR, 'tests/.data/mux-selftest.yaml')
tree_yaml_url = '/:%s' % tree_yaml_path
act = yaml_to_mux.create_from_yaml([tree_yaml_url])
act = mux.apply_filters(act, ('/hw/cpu/intel', '/distro/fedora',
'/hw'))
act = tuple(mux.MuxTree(act))
self.assertEqual(act, exp)
def test_filter_out(self):
act = yaml_to_mux.create_from_yaml(["/:" + PATH_PREFIX +
'selftests/.data/mux-selftest.yaml'])
tree_yaml_path = os.path.join(BASEDIR, 'tests/.data/mux-selftest.yaml')
tree_yaml_url = '/:%s' % tree_yaml_path
act = yaml_to_mux.create_from_yaml([tree_yaml_url])
act = mux.apply_filters(act, None, ('/hw/cpu/intel', '/distro/fedora',
'/distro'))
act = tuple(mux.MuxTree(act))
......@@ -299,8 +291,9 @@ class TestMultiplex(unittest.TestCase):
class TestAvocadoParams(unittest.TestCase):
def setUp(self):
yamls = yaml_to_mux.create_from_yaml(["/:" + PATH_PREFIX +
'selftests/.data/mux-selftest-params.yaml'])
yaml_path = os.path.join(BASEDIR, 'tests/.data/mux-selftest-params.yaml')
yaml_url = '/:%s' % yaml_path
yamls = yaml_to_mux.create_from_yaml([yaml_url])
self.yamls = iter(mux.MuxTree(yamls))
self.params1 = parameters.AvocadoParams(next(self.yamls),
['/ch0/*', '/ch1/*'])
......@@ -309,15 +302,11 @@ class TestAvocadoParams(unittest.TestCase):
self.params2 = parameters.AvocadoParams(next(self.yamls),
['/ch1/*', '/ch0/*'])
@unittest.skipUnless(plugin_available("avocado-framework-plugin-varianter-yaml-to-mux"),
"Plugin avocado_varianter_yaml_to_mux not available")
def test_pickle(self):
params = pickle.dumps(self.params1, 2) # protocol == 2
params = pickle.loads(params)
self.assertEqual(self.params1, params)
@unittest.skipUnless(plugin_available("avocado-framework-plugin-varianter-yaml-to-mux"),
"Plugin avocado_varianter_yaml_to_mux not available")
def test_basic(self):
self.assertEqual(self.params1, self.params1)
self.assertNotEqual(self.params1, self.params2)
......@@ -326,8 +315,6 @@ class TestAvocadoParams(unittest.TestCase):
str(parameters.AvocadoParams([], []))
self.assertEqual(15, sum([1 for _ in iteritems(self.params1)]))
@unittest.skipUnless(plugin_available("avocado-framework-plugin-varianter-yaml-to-mux"),
"Plugin avocado_varianter_yaml_to_mux not available")
def test_unhashable(self):
""" Verifies that unhashable arguments can be passed to params.get """
self.assertEqual(self.params1.get("root", "/ch0/", ["foo"]), ["foo"])
......@@ -335,8 +322,6 @@ class TestAvocadoParams(unittest.TestCase):
'/ch0/ch0.1/ch0.1.1/ch0.1.1.1/',
['bar']), 'unique1')
@unittest.skipUnless(plugin_available("avocado-framework-plugin-varianter-yaml-to-mux"),
"Plugin avocado_varianter_yaml_to_mux not available")
def test_get_abs_path(self):
# /ch0/ is not leaf thus it's not queryable
self.assertEqual(self.params1.get('root', '/ch0/', 'bbb'), 'bbb')
......@@ -358,8 +343,6 @@ class TestAvocadoParams(unittest.TestCase):
'/ch0/ch0.1/ch0.1.1/ch0.1.1.1/',
'hhh'), 'hhh')
@unittest.skipUnless(plugin_available("avocado-framework-plugin-varianter-yaml-to-mux"),
"Plugin avocado_varianter_yaml_to_mux not available")
def test_get_greedy_path(self):
self.assertEqual(self.params1.get('unique1', '/*/*/*/ch0.1.1.1/',
111), 'unique1')
......@@ -383,8 +366,6 @@ class TestAvocadoParams(unittest.TestCase):
# path matches nothing
self.assertEqual(self.params1.get('root', '', 999), 999)
@unittest.skipUnless(plugin_available("avocado-framework-plugin-varianter-yaml-to-mux"),
"Plugin avocado_varianter_yaml_to_mux not available")
def test_get_rel_path(self):
self.assertEqual(self.params1.get('root', default='iii'), 'root')
self.assertEqual(self.params1.get('unique1', '*', 'jjj'), 'unique1')
......@@ -399,8 +380,6 @@ class TestAvocadoParams(unittest.TestCase):
self.assertEqual(self.params2.get('unique1', '*/ch0.1.1.1/', 'ooo'),
'ooo')
@unittest.skipUnless(plugin_available("avocado-framework-plugin-varianter-yaml-to-mux"),
"Plugin avocado_varianter_yaml_to_mux not available")
def test_get_clashes(self):
# One inherited, the other is new
self.assertRaisesRegexp(ValueError, r"'clash1'.* \['/ch0/ch0.1/ch0.1.1"
......@@ -433,15 +412,12 @@ class TestMultipleLoaders(unittest.TestCase):
"""
Verifies that `create_from_yaml` does not affects the main yaml.Loader
"""
nondebug = yaml_to_mux.create_from_yaml(['/:' + PATH_PREFIX +
'selftests/.data/mux-selftest.'
'yaml'])
yaml_path = os.path.join(BASEDIR, 'tests/.data/mux-selftest.yaml')
yaml_url = '/:%s' % yaml_path
nondebug = yaml_to_mux.create_from_yaml([yaml_url])
self.assertEqual(type(nondebug), mux.MuxTreeNode)
self.assertEqual(type(nondebug.children[0]), mux.MuxTreeNode)
debug = yaml_to_mux.create_from_yaml(['/:' + PATH_PREFIX +
'selftests/.data/mux-selftest.'
'yaml'],
debug=True)
debug = yaml_to_mux.create_from_yaml([yaml_url], debug=True)
self.assertEqual(type(debug), mux.MuxTreeNodeDebug)
# Debug nodes are of generated "NamedTreeNodeDebug" type
self.assertEqual("<class 'avocado.core.tree.NamedTreeNodeDebug'>",
......
......@@ -5,6 +5,7 @@ __author__ = 'Lucas Meneghel Rodrigues <lmr@redhat.com>'
import gc
import os
import pkg_resources
import subprocess
import sys
import unittest
......@@ -16,6 +17,14 @@ CHECK_TMP_DIRS = os.path.abspath(os.path.join(os.path.dirname(__file__),
"check_tmp_dirs"))
def plugin_available(plugin_name):
try:
pkg_resources.require(plugin_name)
return True
except pkg_resources.DistributionNotFound:
return False
def test_suite():
suite = unittest.TestSuite()
loader = unittest.TestLoader()
......@@ -24,6 +33,11 @@ def test_suite():
for section in ('unit', 'functional', 'doc'):
suite.addTests(loader.discover(start_dir=os.path.join(selftests_dir, section),
top_level_dir=basedir))
# when other plugins get their own tests, make this a generic loop
if plugin_available('avocado-framework-plugin-varianter-yaml-to-mux'):
path = os.path.join(basedir, 'optional_plugins',
'varianter_yaml_to_mux', 'tests')
suite.addTests(loader.discover(start_dir=path, top_level_dir=path))
return suite
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册