Beispiel #1
0
    def add_test_series(self, _testclass, N=100, chooser=None, filter=None,
                        args=None, kwargs=None):
        """Add a TestCase case as a series.

        The arguments must be lists of possible values for each parameter. The
        args and kwargs arguments are lists that are combined in all possible
        combinations, except pruned to N values. The pruning policy can be
        adjusted by the chooser callback, and the N value itself.

        Args:
            testclass (class): the TestCase class object
                               (subclass of core.TestCase).

            N (integer): Maximum iterations to take from resulting set. Default
                    is 100 just to be safe.

            chooser (callable): callable that takes one number and a list
                    argument, returns a list of the specified (N) length.
                    Default is to chop off the top end of the list.

            filter (callable): callable that takes a set of arguments with the
                               same semantics as the TestCase.execute() method
                               and returns True or False to indicate if that
                               combination should be included in the test. You
                               might want to set a large N if you use this.

            args (tuple): tuple of positional arguments, each argument is a
                          list.  example: args=([1,2,3], [4,5]) maps to
                          positional argumnts of execute() method of TestCase
                          class.

            kwargs (dict): Dictionary of keyword arguments, with list of values
                           as value.
                           example: kwargs={"arg1":["a", "b", "c"]} maps to
                           keyword arguments of execute() method of TestCase
                           class.

        """
        if isinstance(_testclass, str):
            _testclass = module.get_class(_testclass)
        _testclass.set_test_options()
        testinstance = _testclass(self.config, self.environment, self.UI)
        try:
            entry = TestEntrySeries(
                testinstance, N, chooser, filter, args, kwargs)
        except ValueError as err:
            self.info("add_test_series: {}. Not adding {} as series.".format(
                err, _testclass.__name__))
        else:
            # series tests don't get auto-added (can't know what all the args
            # are, and even so the set could be large.)
            mysig, myargsig = entry.signature
            self._multitestset.add(mysig)  # only add by id.
            self._add_with_prereq(entry)
Beispiel #2
0
    def add_test(self, _testclass, *args, **kwargs):
        """Add a TestCase subclass and its arguments to the suite.

    Appends a test object in this suite. The test's ``execute`` will be
    called (at the appropriate time) with the arguments supplied here. If
    the test case has a prerequisite defined it is checked for existence in
    the suite, and an exception is raised if it is not found.
    """
        if isinstance(_testclass, str):
            _testclass = module.get_class(_testclass)
        _testclass.set_test_options()
        testinstance = _testclass(self.config, self.environment, self.UI)
        entry = TestEntry(testinstance, args, kwargs, False)
        self._add_with_prereq(entry)
Beispiel #3
0
    def add_suite(self, suite, test_name=None):
        """Add an entire suite of tests to this suite.

    Appends an embedded test suite in this suite. This is called a sub-suite
    and is treated as a single test by this containing suite.
    """
        if isinstance(suite, str):
            suite = module.get_class(suite)
        if type(suite) is type(TestCase):  # class type
            suite = suite(self.config, 1)
        else:
            suite.config = self.config
            suite._nested = 1
        self._tests.append(SuiteEntry(suite))
        # sub-tests need unique names
        if test_name:
            suite.test_name = test_name
        else:
            # Name plus index into suite list.
            suite.test_name = "%s-%s" % (suite.test_name, len(self._tests)-1)
        return suite