summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2016-10-17 17:08:23 -0700
committerDylan Baker <dylan@pnwbakers.com>2016-11-10 10:51:48 -0800
commit79baff4e6aba5eb5323e2485a5dcab3483c8733a (patch)
tree338a169d5b06f7a1a49046dfb45ec17ecd6011e0 /framework
parentb1d0232cb56f88f82e6e4117d5ecefcffa46e231 (diff)
framework/profile: Move group_manager from TestProfile to TestDict
This move is going to allow us to supplement the TestDict with a different class that can be used instead that loads xml. Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
Diffstat (limited to 'framework')
-rw-r--r--framework/profile.py104
1 files changed, 48 insertions, 56 deletions
diff --git a/framework/profile.py b/framework/profile.py
index 7e09081e6..23abc6d41 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -170,52 +170,6 @@ class TestDict(collections.MutableMapping):
def __iter__(self):
return iter(self.__container)
- @property
- @contextlib.contextmanager
- def allow_reassignment(self):
- """Context manager that allows keys to be reassigned.
-
- Normally reassignment happens in error, but sometimes one actually
- wants to do reassignment, say to add extra options in a reduced
- profile. This method allows reassignment, but only within its context,
- making it an explicit choice to do so.
-
- It is safe to nest this contextmanager.
-
- This is not thread safe, or even co-routine safe.
- """
- self.__allow_reassignment += 1
- yield
- self.__allow_reassignment -= 1
-
-
-class TestProfile(object):
- """Class that holds a list of tests for execution.
-
- This class represents a single testsuite, it has a mapping (dictionary-like
- object) of tests attached (TestDict). This is a mapping of <str>:<Test>
- (python 3 str, python 2 unicode), and the key is delimited by
- grouptools.SEPARATOR.
-
- The group_manager method provides a context_manager to make adding test to
- the test_list easier, by doing more validation and enforcement.
- >>> t = TestProfile()
- >>> with t.group_manager(Test, 'foo@bar') as g:
- ... g(['foo'])
-
- This class does not provide a way to execute itself, instead that is
- handled by the run function in this module, which is able to process and
- run multiple TestProfile objects at once.
- """
- def __init__(self):
- self.test_list = TestDict()
- self.forced_test_list = []
- self.filters = []
- self.options = {
- 'dmesg': get_dmesg(False),
- 'monitor': Monitoring(False),
- }
-
@contextlib.contextmanager
def group_manager(self, test_class, group, **default_args):
"""A context manager to make working with flat groups simple.
@@ -255,16 +209,15 @@ class TestProfile(object):
"""Helper function that actually adds the tests.
Arguments:
- args -- arguments to be passed to the test_class constructor.
- This must be appropriate for the underlying class
+ args -- arguments to be passed to the test_class constructor.
+ This must be appropriate for the underlying class
Keyword Arguments:
- name -- If this is a a truthy value that value will be used as the
- key for the test. If name is falsy then args will be
- ' '.join'd and used as name. Default: None
+ name -- If this is a a truthy value that value will be used as
+ the key for the test. If name is falsy then args will be
+ ' '.join'd and used as name. Default: None
kwargs -- Any additional args will be passed directly to the test
constructor as keyword args.
-
"""
# If there is no name, then either
# a) join the arguments list together to make the name
@@ -281,7 +234,7 @@ class TestProfile(object):
assert isinstance(name, six.string_types)
lgroup = grouptools.join(group, name)
- self.test_list[lgroup] = test_class(
+ self[lgroup] = test_class(
args,
**dict(itertools.chain(six.iteritems(default_args),
six.iteritems(kwargs))))
@@ -291,9 +244,48 @@ class TestProfile(object):
@property
@contextlib.contextmanager
def allow_reassignment(self):
- """A convenience wrapper around self.test_list.allow_reassignment."""
- with self.test_list.allow_reassignment:
- yield
+ """Context manager that allows keys to be reassigned.
+
+ Normally reassignment happens in error, but sometimes one actually
+ wants to do reassignment, say to add extra options in a reduced
+ profile. This method allows reassignment, but only within its context,
+ making it an explicit choice to do so.
+
+ It is safe to nest this contextmanager.
+
+ This is not thread safe, or even co-routine safe.
+ """
+ self.__allow_reassignment += 1
+ yield
+ self.__allow_reassignment -= 1
+
+
+class TestProfile(object):
+ """Class that holds a list of tests for execution.
+
+ This class represents a single testsuite, it has a mapping (dictionary-like
+ object) of tests attached (TestDict). This is a mapping of <str>:<Test>
+ (python 3 str, python 2 unicode), and the key is delimited by
+ grouptools.SEPARATOR.
+
+ The group_manager method provides a context_manager to make adding test to
+ the test_list easier, by doing more validation and enforcement.
+ >>> t = TestProfile()
+ >>> with t.group_manager(Test, 'foo@bar') as g:
+ ... g(['foo'])
+
+ This class does not provide a way to execute itself, instead that is
+ handled by the run function in this module, which is able to process and
+ run multiple TestProfile objects at once.
+ """
+ def __init__(self):
+ self.test_list = TestDict()
+ self.forced_test_list = []
+ self.filters = []
+ self.options = {
+ 'dmesg': get_dmesg(False),
+ 'monitor': Monitoring(False),
+ }
def setup(self):
"""Method to do pre-run setup."""