[Piglit] [RFC v2 31/39] profile.py: Add kwargs to TestProfile.group_manager
Dylan Baker
baker.dylan.c at gmail.com
Mon Feb 2 17:37:36 PST 2015
This adds the ability for the group_manager method to take additional
keyword arguments that are passed to the underlying Test constructor.
This allows groups that all need the same arguments (say platform
requirements), but be passed to the constructor and be added by the
adder.
>>> prof = TestProfile()
>>> with prof.group_manater(Test, 'group', required_platforms=['glx']) as g:
... g(['glx-foobar'])
>>> prof.test_list['group/glx-foobar'].required-platforms == ['glx']
True
---
framework/profile.py | 14 ++++++++++++--
framework/tests/profile_tests.py | 30 ++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/framework/profile.py b/framework/profile.py
index 3a30e99..ab86717 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -34,6 +34,7 @@ import multiprocessing.dummy
import importlib
import types
import contextlib
+import itertools
from framework.dmesg import get_dmesg
from framework.log import LogManager
@@ -271,7 +272,7 @@ class TestProfile(object):
self.test_list.update(profile.test_list)
@contextlib.contextmanager
- def group_manager(self, test_class, group):
+ def group_manager(self, test_class, group, prefix=None, **default_args):
"""A context manager to make working with flat groups simple.
This provides a simple way to replace add_plain_test,
@@ -291,6 +292,12 @@ class TestProfile(object):
group -- a string or unicode that will be used as the key for the test
in profile.
+ Keyword Arguments:
+ **default_args -- any additional keyword arguments will be considered
+ default arguments to all tests added by the adder.
+ They will always be overwritten by **kwargs passed to
+ the adder function
+
>>> from framework.test import PiglitGLTest
>>> p = TestProfile()
>>> with p.group_manager(PiglitGLTest, 'a') as g:
@@ -321,7 +328,10 @@ class TestProfile(object):
assert isinstance(name, basestring)
lgroup = grouptools.join(group, name)
- self.test_list[lgroup] = test_class(args, **kwargs)
+ self.test_list[lgroup] = test_class(
+ args,
+ **{k:v for k, v in itertools.chain(default_args.iteritems(),
+ kwargs.iteritems())})
yield adder
diff --git a/framework/tests/profile_tests.py b/framework/tests/profile_tests.py
index 8f9dba0..a114300 100644
--- a/framework/tests/profile_tests.py
+++ b/framework/tests/profile_tests.py
@@ -215,3 +215,33 @@ def test_testprofile_group_manager_is_added():
g(['a', 'b'], 'a')
nt.assert_in(grouptools.join('foo', 'a'), prof.test_list)
+
+
+def test_testprofile_groupmanager_kwargs():
+ """TestProfile.group_manager: Extra kwargs are passed to the Test."""
+ prof = profile.TestProfile()
+ with prof.group_manager(utils.Test, 'foo') as g:
+ g(['a'], run_concurrent=True)
+
+ test = prof.test_list[grouptools.join('foo', 'a')]
+ nt.assert_equal(test.run_concurrent, True)
+
+
+def test_testprofile_groupmanager_default_args():
+ """TestProfile.group_manager: group_manater kwargs are passed to the Test."""
+ prof = profile.TestProfile()
+ with prof.group_manager(utils.Test, 'foo', run_concurrent=True) as g:
+ g(['a'])
+
+ test = prof.test_list[grouptools.join('foo', 'a')]
+ nt.assert_equal(test.run_concurrent, True)
+
+
+def test_testprofile_groupmanager_kwargs_overwrite():
+ """TestProfile.group_manager: default_args are overwritten by kwargs."""
+ prof = profile.TestProfile()
+ with prof.group_manager(utils.Test, 'foo', run_concurrent=True) as g:
+ g(['a'], run_concurrent=False)
+
+ test = prof.test_list[grouptools.join('foo', 'a')]
+ nt.assert_equal(test.run_concurrent, False)
--
2.2.2
More information about the Piglit
mailing list