summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2015-01-27 16:07:44 -0800
committerDylan Baker <baker.dylan.c@gmail.com>2015-03-05 09:46:47 -0800
commitf735cbfa5d27dddb0fed43e74a12c7856b58eeff (patch)
tree341380fa5567db8aebdd7f351b021f40f597b520
parentac687d0a5cbc92bdca90d9b7f5d9a518968f8836 (diff)
profile.py: Add kwargs to TestProfile.group_manager
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
-rw-r--r--framework/profile.py14
-rw-r--r--framework/tests/profile_tests.py30
2 files changed, 42 insertions, 2 deletions
diff --git a/framework/profile.py b/framework/profile.py
index 6d40d0ae7..e8e8ba18f 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 0103de406..d2878c3c4 100644
--- a/framework/tests/profile_tests.py
+++ b/framework/tests/profile_tests.py
@@ -211,3 +211,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)