示例#1
0
 def test_get_all_args(self):
     empty = inspect._empty
     self.assertEqual(get_all_args(AllKindsOfSettingsDependentBear.run),
                      {'self': empty, 'file': empty, 'filename': empty,
                       'configs': empty,
                       'use_bears': empty, 'no_lines': empty,
                       'use_spaces': None,
                       'use_tabs': False, 'max_line_lengths': 1000,
                       'no_chars': 79,
                       'chars': False, 'dependency_results': {}})
def in_all_args(func, key):
    """
    Checks if a setting name as key is present in function
    arguments.
    :param func:
        Function object.
    :param key:
        The setting name as a string.
    :return:
        True if key is present in args of a function else False.
    """
    return True if key in get_all_args(func) else False
def in_all_args(func, key):
    """
    Checks if a setting name as key is present in function
    arguments.
    :param func:
        Function object.
    :param key:
        The setting name as a string.
    :return:
        True if key is present in args of a function else False.
    """
    return True if key in get_all_args(func) else False
 def parse_dep_tree_non_optional(self, bear, key):
     """
     Parses the bear's dependency tree looking for
     non-optional setting and their Type.
     :param bear:
         The bear object.
     :param key:
         The setting value as a string.
     """
     deps = bear.BEAR_DEPS
     for dep in deps:
         present_in_annot = in_annot(dep.run, key)
         if present_in_annot:
             self.diff_bool_others(key, present_in_annot)
         else:
             settings = get_all_args(dep.run)
             for pointer in get_default_args(dep.run):
                 del settings[pointer]
             if key in settings:
                 self.diff_bool_others(key, settings[key])
         self.parse_dep_tree_non_optional(dep, key)
 def parse_dep_tree_non_optional(self, bear, key):
     """
     Parses the bear's dependency tree looking for
     non-optional setting and their Type.
     :param bear:
         The bear object.
     :param key:
         The setting value as a string.
     """
     deps = bear.BEAR_DEPS
     for dep in deps:
         present_in_annot = in_annot(dep.run, key)
         if present_in_annot:
             self.diff_bool_others(key, present_in_annot)
         else:
             settings = get_all_args(dep.run)
             for pointer in get_default_args(dep.run):
                 del settings[pointer]
             if key in settings:
                 self.diff_bool_others(key, settings[key])
         self.parse_dep_tree_non_optional(dep, key)
    def fillup_non_optional_settings(self, key, funcs, bear):
        """
        Function to populate the non-optional settings
        for the classes to store metadata.
        :param key:
            The setting value as a string.
        :param funcs:
            A list of function objects i.e. either containing the run() method
            or the create_arguments() and generate_config() methods of the
            linter bears.
        :param bear:
            The bear object.
        """
        present_in_annot = False
        present_in_default_args = False
        present_in_all_args = False
        function = None

        for func in funcs:
            present_in_annot = in_annot(func, key)
            if present_in_annot:
                break

        for func in funcs:
            present_in_default_args = in_default_args(func, key)
            if present_in_default_args:
                break

        for func in funcs:
            present_in_all_args = in_all_args(func, key)
            if present_in_all_args:
                function = func
                break

        if present_in_annot:
            self.diff_bool_others(key, present_in_annot)
        elif present_in_all_args and not present_in_default_args:
            self.diff_bool_others(key, get_all_args(function)[key])
        else:
            self.parse_dep_tree_non_optional(bear, key)
    def fillup_non_optional_settings(self, key, funcs, bear):
        """
        Function to populate the non-optional settings
        for the classes to store metadata.
        :param key:
            The setting value as a string.
        :param funcs:
            A list of function objects i.e. either containing the run() method
            or the create_arguments() and generate_config() methods of the
            linter bears.
        :param bear:
            The bear object.
        """
        present_in_annot = False
        present_in_default_args = False
        present_in_all_args = False
        function = None

        for func in funcs:
            present_in_annot = in_annot(func, key)
            if present_in_annot:
                break

        for func in funcs:
            present_in_default_args = in_default_args(func, key)
            if present_in_default_args:
                break

        for func in funcs:
            present_in_all_args = in_all_args(func, key)
            if present_in_all_args:
                function = func
                break

        if present_in_annot:
            self.diff_bool_others(key, present_in_annot)
        elif present_in_all_args and not present_in_default_args:
            self.diff_bool_others(key, get_all_args(function)[key])
        else:
            self.parse_dep_tree_non_optional(bear, key)
    def fillup_non_optional_settings(self, key, func, bear):
        """
        Function to populate the non-optional settings
        for the classes to store metadata.
        :param key:
            The setting value as a string.
        :param func:
            The function object. Either create_arguments() for linter bears
            or run() for other bears.
        :param bear:
            The bear object.
        """
        present_in_annot = in_annot(func, key)
        present_in_default_args = in_default_args(func, key)
        present_in_all_args = in_all_args(func, key)

        if present_in_annot:
            self.diff_bool_others(key, present_in_annot)
        elif present_in_all_args and not present_in_default_args:
            self.diff_bool_others(key, get_all_args(func)[key])
        else:
            self.parse_dep_tree(bear, key)
示例#9
0
def local_bear_test(
    bear,
    file_dict,
    file_names,
    lang,
    kwargs,
    ignore_ranges,
    jobs: int = 0,
):
    lang_files = split_by_language(file_names)
    lang_files = {k.lower(): v for k, v in lang_files.items()}

    pool = _create_mp_pool(jobs)

    file_results = []

    for file in lang_files[lang.lower()]:
        kwargs['filename'] = [file]
        kwargs['file'] = [file_dict[file]]

        results = []
        values = []

        for vals in itertools.product(*kwargs.values()):

            flag = 0
            for dep in bear.BEAR_DEPS:
                section = Section('dep-bear')
                bear_obj = dep(section, None)
                arguments = dict(zip(kwargs, vals))
                dep_args = get_all_args(dep.run)
                new_arguments = {}
                for arg_ in arguments.keys():
                    if arg_ in dep_args.keys():  # pragma: no cover
                        new_arguments[arg_] = arguments[arg_]
                arguments = new_arguments
                ret_val = bear_obj.run(**arguments)
                ret_val = [] if not ret_val else list(ret_val)
                dep_res = check_bear_results(ret_val, ignore_ranges)
                if not dep_res:
                    flag = 1
            if flag == 1:
                continue

            print_val = dict(zip(kwargs, vals))
            print_val.pop('file', None)
            values.append(vals)
            section = Section('test-section-local-bear')
            bear_obj = bear(section, None)
            ret_val = bear_obj.run(**dict(zip(kwargs, vals)))
            ret_val = [] if not ret_val else list(ret_val)
            if pool:  # pragma Python 3.5: no cover; pragma nt: no cover
                results.append(
                    pool.apply(check_bear_results,
                               args=(ret_val, ignore_ranges)))
            else:  # pragma Python 3.4,3.6,3.7: no cover
                results.append(check_bear_results(ret_val, ignore_ranges))

        for index, result in enumerate(results):
            if result is True:
                # A set of bear setting values is found to be green
                # for a particular file
                arguments = dict(zip(kwargs, values[index]))
                arguments.pop('file')
                file_results.append(arguments)

    return {bear: file_results}
def local_bear_test(bear, file_dict, file_names, lang, kwargs,
                    ignore_ranges,
                    jobs: int = 0,
                    ):
    lang_files = split_by_language(file_names)
    lang_files = {k.lower(): v for k, v in lang_files.items()}

    pool = _create_mp_pool(jobs)

    file_results = []

    for file in lang_files[lang.lower()]:
        kwargs['filename'] = [file]
        kwargs['file'] = [file_dict[file]]

        results = []
        values = []

        for vals in itertools.product(*kwargs.values()):

            flag = 0
            for dep in bear.BEAR_DEPS:
                section = Section('dep-bear')
                bear_obj = dep(section, None)
                arguments = dict(zip(kwargs, vals))
                dep_args = get_all_args(dep.run)
                new_arguments = {}
                for arg_ in arguments.keys():
                    if arg_ in dep_args.keys():  # pragma: no cover
                        new_arguments[arg_] = arguments[arg_]
                arguments = new_arguments
                ret_val = bear_obj.run(**arguments)
                ret_val = [] if not ret_val else list(ret_val)
                dep_res = check_bear_results(ret_val, ignore_ranges)
                if not dep_res:
                    flag = 1
            if flag == 1:
                continue

            print_val = dict(zip(kwargs, vals))
            print_val.pop('file', None)
            values.append(vals)
            section = Section('test-section-local-bear')
            bear_obj = bear(section, None)
            ret_val = bear_obj.run(**dict(zip(kwargs, vals)))
            ret_val = [] if not ret_val else list(ret_val)
            if pool:  # pragma Python 3.5: no cover; pragma nt: no cover
                results.append(pool.apply(check_bear_results,
                                          args=(ret_val, ignore_ranges)))
            else:  # pragma Python 3.4,3.6,3.7: no cover
                results.append(check_bear_results(ret_val, ignore_ranges))

        for index, result in enumerate(results):
            if result is True:
                # A set of bear setting values is found to be green
                # for a particular file
                arguments = dict(zip(kwargs, values[index]))
                arguments.pop('file')
                file_results.append(arguments)

    return {bear: file_results}