Beispiel #1
0
    def __init__(self,
                 name,
                 description=None,
                 category=None,
                 uid=None,
                 entries=None,
                 tags=None,
                 part=None,
                 fix_spec_path=None):
        super(TestGroupReport, self).__init__(name=name,
                                              description=description,
                                              uid=uid,
                                              entries=entries)

        # This will be used for distinguishing test
        # type (Multitest, GTest etc)
        self.category = category

        self.tags = tagging.validate_tag_value(tags) if tags else {}
        self.tags_index = copy.deepcopy(self.tags)

        # A test can be split into many parts and the report of each part
        # can be hold back for merging (if necessary)
        self.part = part  # i.e. (m, n), while 0 <= m < n and n > 1
        self.part_report_lookup = {}

        self.fix_spec_path = fix_spec_path

        if entries:
            self.propagate_tag_indices()
Beispiel #2
0
def _generate_func(function, name_func, tag_func, docstring_func, tag_dict,
                   kwargs):
    """
    Generates a new function using the original function, name generation
    function and parametrized kwargs.

    Also attaches parametrized and explicit tags and apply custom wrappers.
    """
    def _generated(self, env, result):
        return function(self, env, result, **kwargs)

    _generated.__doc__ = docstring_func(function.__doc__, kwargs)\
        if docstring_func else None

    _generated.__name__ = _name_func_wrapper(name_func=name_func,
                                             func_name=function.__name__,
                                             kwargs=kwargs)

    # Tags generated via `tag_func` will be assigned as native tags
    _generated.__tags__ = tagging.validate_tag_value(tag_func(kwargs)) \
        if tag_func else {}

    # Tags index will be merged tag ctx of tag_dict & generated tags
    _generated.__tags_index__ = tagging.merge_tag_dicts(
        _generated.__tags__, tag_dict)

    _generated._parametrization_template = function.__name__

    return _generated
Beispiel #3
0
def _generate_func(function, name_func, tag_func, docstring_func, tags,
                   kwargs):
    """
    Generates a new function using the original function, name generation
    function and parametrized kwargs.

    Also attaches parametrized and explicit tags and apply custom wrappers.
    """
    def _generated(self, env, result):
        return function(self, env, result, **kwargs)

    _generated.__doc__ = docstring_func(function.__doc__, kwargs)\
        if docstring_func else None
    _generated.__name__ = _name_func_wrapper(name_func=name_func,
                                             func_name=function.__name__,
                                             kwargs=kwargs)

    # Tagging
    parametrized_tags = tagging.validate_tag_value(tag_func(kwargs))\
        if tag_func else {}
    tagging.attach_testcase_tags(
        _generated, tagging.merge_tag_dicts(tags, parametrized_tags))

    _generated._parametrization_template = function.__name__

    return _generated
Beispiel #4
0
    def __init__(self,
                 name,
                 category=ReportCategories.TESTGROUP,
                 tags=None,
                 part=None,
                 extra_attributes=None,
                 fix_spec_path=None,
                 env_status=None,
                 **kwargs):
        super(TestGroupReport, self).__init__(name=name, **kwargs)

        # This will be used for distinguishing test type (Multitest, GTest
        # etc). Expected to be one of the ReportCategories enum, otherwise
        # the report node will not be correctly rendered in the UI.
        self.category = category

        self.tags = tagging.validate_tag_value(tags) if tags else {}
        self.tags_index = copy.deepcopy(self.tags)

        # A test can be split into many parts and the report of each part
        # can be hold back for merging (if necessary)
        self.part = part  # i.e. (m, n), while 0 <= m < n and n > 1
        self.part_report_lookup = {}

        self.extra_attributes = extra_attributes or {}

        self.fix_spec_path = fix_spec_path

        if self.entries:
            self.propagate_tag_indices()

        # Expected to be one of ResourceStatus, or None.
        self.env_status = env_status
Beispiel #5
0
    def wrapper(klass):
        """Meta logic for suite goes here."""
        if custom_name is None or isinstance(custom_name, six.string_types):
            pass
        elif callable(custom_name):
            try:
                interface.check_signature(
                    custom_name, ["self", "original_name"]
                )
            except interface.MethodSignatureMismatch as err:
                _reset_globals()
                raise err
        else:
            _reset_globals()
            raise TypeError("`custom_name` should be callable or a string")

        klass.custom_name = custom_name

        if tags:
            klass.__tags__ = tagging.validate_tag_value(tags)
            klass.__tags_index__ = copy.deepcopy(klass.__tags__)
        else:
            klass.__tags__ = {}
            klass.__tags_index__ = {}

        return _testsuite(klass)
Beispiel #6
0
    def wrapper(function):
        """Meta logic for test case goes here"""

        tag_dict = tagging.validate_tag_value(tags) if tags else {}
        function.__tags__ = tag_dict.copy()
        function.__tags_index__ = tag_dict.copy()

        if parameters is not None:  # Empty tuple / dict checks happen later

            function.__parametrization_template__ = True

            functions = parametrization.generate_functions(
                function=function,
                parameters=parameters,
                name_func=name_func,
                docstring_func=docstring_func,
                tag_func=tag_func,
                tag_dict=tag_dict,
                summarize=summarize,
                num_passing=defaults.SUMMARY_NUM_PASSING,
                num_failing=defaults.SUMMARY_NUM_FAILING)

            # Register generated functions as test_cases
            for func in functions:
                _validate_testcase(func)
                # this has to be called before wrappers otherwise wrappers can
                # fail if they rely on __testcase__
                _mark_function_as_testcase(func)

                wrappers = custom_wrappers or []

                if not isinstance(wrappers, (list, tuple)):
                    wrappers = [wrappers]

                for wrapper_func in wrappers:
                    func = wrapper_func(func)

                # so that CodeDetails gets the correct line number
                func.wrapper_of = function

                __TESTCASES__.append(func.__name__)
                __GENERATED_TESTCASES__.append(func)

            # Update template method's tag index with generated
            # testcases' tag indices. This will have no effect of test
            # filtering logic, however generated test reports
            # may need this data for report filtering.
            if tag_func:
                update_tag_index(function,
                                 tag_dict=collect_testcase_tags(functions))

            return function
        else:
            function.summarize = summarize
            function.summarize_num_passing = num_passing
            function.summarize_num_failing = num_failing

            return _testcase(function)
Beispiel #7
0
    def wrapper(function):
        """Meta logic for test case goes here"""

        tag_dict = tagging.validate_tag_value(tags) if tags else {}
        function.__tags__ = copy.deepcopy(tag_dict)

        if parameters is not None:  # Empty tuple / dict checks happen later

            function.__parametrization_template__ = True

            functions = parametrization.generate_functions(
                function=function,
                parameters=parameters,
                name_func=name_func,
                docstring_func=docstring_func,
                tag_func=tag_func,
                tag_dict=tag_dict,
                summarize=summarize,
                num_passing=num_passing,
                num_failing=num_failing,
                key_combs_limit=key_combs_limit,
                execution_group=execution_group,
                timeout=timeout
            )

            # Register generated functions as test_cases
            for func in functions:
                _validate_testcase(func)
                # this has to be called before wrappers otherwise wrappers can
                # fail if they rely on __testcase__
                _mark_function_as_testcase(func)

                wrappers = custom_wrappers or []

                if not isinstance(wrappers, (list, tuple)):
                    wrappers = [wrappers]

                for wrapper_func in wrappers:
                    func = wrapper_func(func)

                # so that CodeDetails gets the correct line number
                func.wrapper_of = function

                __TESTCASES__.append(func.__name__)
                __GENERATED_TESTCASES__.append(func)

            return function
        else:
            function.summarize = summarize
            function.summarize_num_passing = num_passing
            function.summarize_num_failing = num_failing
            function.summarize_key_combs_limit = key_combs_limit
            function.execution_group = execution_group
            function.timeout = timeout
            function.__tags_index__ = copy.deepcopy(tag_dict)

            return _testcase(function)
Beispiel #8
0
    def wrapper(klass):
        """Meta logic for suite goes here"""
        if tags:
            klass.__tags__ = tagging.validate_tag_value(tags)
            klass.__tags_index__ = copy.deepcopy(klass.__tags__)

        suite = _testsuite(klass)

        return suite
Beispiel #9
0
    def wrapper(klass):
        """Meta logic for suite goes here."""
        klass.name = name

        if tags:
            klass.__tags__ = tagging.validate_tag_value(tags)
            klass.__tags_index__ = copy.deepcopy(klass.__tags__)
        else:
            klass.__tags__ = {}
            klass.__tags_index__ = {}

        return _testsuite(klass)
Beispiel #10
0
        def _filter_func(obj):
            # Include all testcase entries, which are in dict form
            if isinstance(obj, dict):
                return True

            tag_dict = tagging.validate_tag_value(tag_value)
            if all_tags:
                match_func = tagging.check_all_matching_tags
            else:
                match_func = tagging.check_any_matching_tags

            return match_func(tag_arg_dict=tag_dict,
                              target_tag_dict=obj.tags_index)
Beispiel #11
0
    def __init__(self,
                 name,
                 description=None,
                 uid=None,
                 entries=None,
                 tags=None):
        super(TestCaseReport, self).__init__(name=name,
                                             uid=uid,
                                             entries=entries,
                                             description=description)

        self.tags = tagging.validate_tag_value(tags) if tags else {}
        self.tags_index = copy.deepcopy(self.tags)

        self.status_override = None
        self.timer = timing.Timer()
Beispiel #12
0
def _generate_func(
    function, name, name_func, tag_func, docstring_func, tag_dict, kwargs
):
    """
    Generates a new function using the original function, name generation
    function and parametrized kwargs.

    Also attaches parametrized and explicit tags and apply custom wrappers.
    """

    def _generated(self, env, result):
        return function(self, env, result, **kwargs)

    # If we were given a docstring function, we use it to generate the
    # docstring for each testcase. Otherwise we just copy the docstring from
    # the template method.
    if docstring_func:
        _generated.__doc__ = docstring_func(function.__doc__, kwargs)
    else:
        _generated.__doc__ = function.__doc__

    _generated.__name__ = _parametrization_name_func_wrapper(
        func_name=function.__name__, kwargs=kwargs
    )
    _generated.name = name_func(name, kwargs) if name_func else name

    if hasattr(function, "__xfail__"):
        _generated.__xfail__ = function.__xfail__

    # Tags generated via `tag_func` will be assigned as native tags
    _generated.__tags__ = (
        tagging.validate_tag_value(tag_func(kwargs)) if tag_func else {}
    )

    # Tags index will be merged tag ctx of tag_dict & generated tags
    _generated.__tags_index__ = tagging.merge_tag_dicts(
        _generated.__tags__, tag_dict
    )

    _generated._parametrization_template = function.__name__
    _generated._parametrization_kwargs = kwargs

    return _generated
Beispiel #13
0
    def __init__(self,
                 name,
                 description=None,
                 uid=None,
                 entries=None,
                 tags=None,
                 suite_related=False):
        super(TestCaseReport, self).__init__(name=name,
                                             uid=uid,
                                             entries=entries,
                                             description=description)

        self.tags = tagging.validate_tag_value(tags) if tags else {}
        self.tags_index = copy.deepcopy(self.tags)
        self.suite_related = suite_related

        self.status_override = None
        self.timer = timing.Timer()

        self.attachments = []
        self._status = Status.READY
Beispiel #14
0
    def __init__(self,
                 name,
                 description=None,
                 category=None,
                 uid=None,
                 entries=None,
                 tags=None):
        super(TestGroupReport, self).__init__(name=name,
                                              uid=uid,
                                              entries=entries,
                                              description=description)

        # This will be used for distinguishing test
        # type (Multitest, GTest etc)
        self.category = category

        self.tags = tagging.validate_tag_value(tags) if tags else {}
        self.tags_index = copy.deepcopy(self.tags)

        if entries:
            self.propagate_tag_indices()
Beispiel #15
0
    def __init__(self,
                 name,
                 tags=None,
                 suite_related=False,
                 status_override=None,
                 status_reason=None,
                 **kwargs):
        super(TestCaseReport, self).__init__(name=name, **kwargs)

        self.tags = tagging.validate_tag_value(tags) if tags else {}
        self.tags_index = copy.deepcopy(self.tags)
        self.suite_related = suite_related

        self.status_override = status_override
        self.timer = timing.Timer()

        self.attachments = []
        # testcase is default to passed (e.g no assertion)
        self._status = Status.UNKNOWN
        self._runtime_status = RuntimeStatus.READY
        self.category = ReportCategories.TESTCASE
        self.status_reason = status_reason
Beispiel #16
0
 def __init__(self, tags):
     self.tags_orig = tags
     self.tags = tagging.validate_tag_value(tags)
Beispiel #17
0
    def wrapper(function):
        """Meta logic for test case goes here."""
        global __GENERATED_TESTCASES__
        global __PARAMETRIZATION_TEMPLATE__

        _validate_function_name(function)
        function.name = name or function.__name__

        tag_dict = tagging.validate_tag_value(tags) if tags else {}
        function.__tags__ = copy.deepcopy(tag_dict)

        if parameters is not None:  # Empty tuple / dict checks happen later
            function.__parametrization_template__ = True
            __PARAMETRIZATION_TEMPLATE__.append(function.__name__)

            try:
                functions = parametrization.generate_functions(
                    function=function,
                    name=function.name,
                    parameters=parameters,
                    name_func=name_func,
                    docstring_func=docstring_func,
                    tag_func=tag_func,
                    tag_dict=tag_dict,
                    summarize=summarize,
                    num_passing=num_passing,
                    num_failing=num_failing,
                    key_combs_limit=key_combs_limit,
                    execution_group=execution_group,
                    timeout=timeout,
                )
            except parametrization.ParametrizationError as err:
                # Testplan stops execution if `ParametrizationError` raises.
                # However in our test the process will not quit but continue
                # to run the next testcase, and module will not be reloaded.
                # So, it is better reset globals before raising this error.
                _reset_globals()
                raise err

            # Register generated functions as testcases
            for func in functions:
                _validate_testcase(func)
                # this has to be called before wrappers otherwise wrappers can
                # fail if they rely on __testcase__
                _mark_function_as_testcase(func)

                wrappers = custom_wrappers or []
                if not isinstance(wrappers, (list, tuple)):
                    wrappers = [wrappers]

                for wrapper_func in wrappers:
                    func = wrapper_func(func)

                # so that CodeDetails gets the correct line number
                func.wrapper_of = function

                func.__seq_number__ = _number_of_testcases()
                __GENERATED_TESTCASES__.append(func)

            return function

        else:
            function.summarize = summarize
            function.summarize_num_passing = num_passing
            function.summarize_num_failing = num_failing
            function.summarize_key_combs_limit = key_combs_limit
            function.execution_group = execution_group
            function.timeout = timeout
            function.__tags_index__ = copy.deepcopy(tag_dict)

            return _testcase(function)
Beispiel #18
0
def generate_functions(
    function,
    parameters,
    name_func,
    tags,
    tag_func,
    docstring_func,
    summarize,
    num_passing,
    num_failing,
):
    """
    Generate test cases using the given parameter context, use the name_func
    to generate the name.

    If parameters is of type ``tuple`` / ``list`` then a new testcase method
    will be created for each item.

    If parameters is of type ``dict`` (of ``tuple``/``list``), then a new
    method will be created for each item in the Cartesian product of all
    combinations of values.

    :param function: A testcase method, with extra
                     arguments for parametrization.
    :type function: ``callable``
    :param parameters: Parametrization context for the test case method.
    :type parameters: ``list`` or ``tuple`` of ``dict`` or ``tuple`` / ``list``
                      OR a ``dict`` of ``tuple`` / ``list``.
    :param name_func: Function that will generate method names,
                      should accept ``func_name`` and ``kwargs`` as parameters.
    :type name_func: ``callable``
    :param docstring_func: Function that will generate docstring,
                      should accept ``docstring`` and ``kwargs`` as parameters.
    :type docstring_func: ``callable``
    :param tag_func: Function that will be used for generating tags via
                     parametrization kwargs. Should accept ``kwargs`` as
                     parameter.
    :type tag_func: ``callable``
    :param tags: Tag annotations to be used for each generated testcase.
    :type tag_func: ``dict`` of ``frozenset``
    :param summarize: Flag for enabling testcase level
                      summarization of all assertions.
    :type summarize: ``bool``
    :param num_passing: Max number of passing assertions
                       for testcase level assertion summary.
    :type num_passing: ``int``
    :param num_failing: Max number of failing assertions
                       for testcase level assertion summary.
    :type num_failing: ``int``
    :return: List of functions that is testcase compliant
             (accepts ``self``, ``env``, ``result`` as arguments) and have
             unique names.
    :rtype: ``list``
    """
    if not parameters:
        raise ParametrizationError('"parameters" cannot be a empty.')

    _check_name_func(name_func)

    argspec = inspect.getargspec(function)
    args = argspec.args[3:]  # get rid of self, env, result
    defaults = (argspec.defaults or [])

    required_args = args[:-len(defaults)] if defaults else args
    default_args = dict(zip(args[len(required_args):], defaults))

    # Need to validate beforehand so we can merge with parametrized_tags
    tags = tagging.validate_tag_value(tags) if tags else {}

    kwarg_list = _generate_kwarg_list(parameters, args, required_args,
                                      default_args)

    functions = [
        _generate_func(function=function,
                       name_func=name_func,
                       tag_func=tag_func,
                       docstring_func=docstring_func,
                       tags=tags,
                       kwargs=kwargs) for kwargs in kwarg_list
    ]

    for func in functions:
        func.summarize = summarize
        func.summarize_num_passing = num_passing
        func.summarize_num_failing = num_failing

    _ensure_unique_names(functions)

    return functions