Exemple #1
0
 def test_get_default_args(self):
     self.assertEqual(get_default_args(AllKindsOfSettingsDependentBear.run),
                      {'chars': False,
                       'dependency_results': {},
                       'max_line_lengths': 1000,
                       'no_chars': 79,
                       'use_spaces': None,
                       'use_tabs': False})
    def __init__(self, bear):
        """
        :param bear:
            A bear class object.
        """
        self.bear = bear
        functions = None
        function = bear.create_arguments if ('create_arguments'
                                             in dir(bear)) else bear.run
        function_name = 'create_arguments' if ('create_arguments'
                                               in dir(bear)) else 'run'
        non_optional_settings = bear.get_non_optional_settings()

        # Get the actual function if the function is decorated.
        original_function = search_for_orig(function, function_name)
        if original_function is not None:
            function = original_function

        if function_name is 'run':
            # Recursively look for optional settings (which have a default
            # value) inside BEAR_DEPS
            optional_settings = get_default_args(function)
            optional_settings.update(parse_dep_tree_optional(self.bear))
            functions = [function]
        else:
            optional_settings_create_arguments = get_default_args(function)
            optional_settings_generate_config = {}
            # Appending the default arguments of bear method generate_config()
            # to those, with that of create_arguments().
            if hasattr(bear, 'generate_config'):
                gen_config_func = bear.generate_config
                # Again getting the actual method if it is decorated.
                gen_config = search_for_orig(gen_config_func,
                                             'generate_config')
                if gen_config is not None:
                    gen_config_func = gen_config
                optional_settings_generate_config = get_default_args(
                    gen_config_func)
                functions = [function, gen_config_func]
            optional_settings_create_arguments.update(
                optional_settings_generate_config)
            optional_settings = optional_settings_create_arguments
            functions = [function] if functions is None else functions

        self.create_setting_types_obj(optional_settings, non_optional_settings,
                                      functions, bear)
    def __init__(self, bear):
        """
        :param bear:
            A bear class object.
        """
        self.bear = bear
        functions = None
        function = bear.create_arguments if (
            'create_arguments' in dir(bear)) else bear.run
        function_name = 'create_arguments' if (
            'create_arguments' in dir(bear)) else 'run'
        non_optional_settings = bear.get_non_optional_settings()

        # Get the actual function if the function is decorated.
        original_function = search_for_orig(function, function_name)
        if original_function is not None:
            function = original_function

        if function_name is 'run':
            # Recursively look for optional settings (which have a default
            # value) inside BEAR_DEPS
            optional_settings = get_default_args(function)
            optional_settings.update(parse_dep_tree_optional(self.bear))
            functions = [function]
        else:
            optional_settings_create_arguments = get_default_args(function)
            optional_settings_generate_config = {}
            # Appending the default arguments of bear method generate_config()
            # to those, with that of create_arguments().
            if hasattr(bear, 'generate_config'):
                gen_config_func = bear.generate_config
                # Again getting the actual method if it is decorated.
                gen_config = search_for_orig(gen_config_func,
                                             'generate_config')
                if gen_config is not None:
                    gen_config_func = gen_config
                optional_settings_generate_config = get_default_args(
                    gen_config_func)
                functions = [function, gen_config_func]
            optional_settings_create_arguments.update(
                optional_settings_generate_config)
            optional_settings = optional_settings_create_arguments
            functions = [function] if functions is None else functions

        self.create_setting_types_obj(optional_settings, non_optional_settings,
                                      functions, bear)
def in_default_args(func, key):
    """
    Checks if a setting name as key is present in function
    arguments with default value.
    :param func:
        Function object.
    :param key:
        The setting name as a string.
    :return:
        True if key is present in args with default value else False.
    """
    return True if key in get_default_args(func) else False
def in_default_args(func, key):
    """
    Checks if a setting name as key is present in function
    arguments with default value.
    :param func:
        Function object.
    :param key:
        The setting name as a string.
    :return:
        True if key is present in args with default value else False.
    """
    return True if key in get_default_args(func) else False
def parse_dep_tree_optional(bear):
    """
    Parse the dependency tree of the bears looking for optional settings.
    :param bear:
        The bear object for which to get optional settings and parse the
        dependency tree further.
    :return:
        Dict of optional settings of the current bear and recursively
        all the optional settings of its dependencies.
    """
    deps = bear.BEAR_DEPS
    optional_settings = get_default_args(bear.run)
    for dep in deps:
        optional_settings.update(parse_dep_tree_optional(dep))
    return optional_settings
def parse_dep_tree_optional(bear):
    """
    Parse the dependency tree of the bears looking for optional settings.
    :param bear:
        The bear object for which to get optional settings and parse the
        dependency tree further.
    :return:
        Dict of optional settings of the current bear and recursively
        all the optional settings of its dependencies.
    """
    deps = bear.BEAR_DEPS
    optional_settings = get_default_args(bear.run)
    for dep in deps:
        optional_settings.update(parse_dep_tree_optional(dep))
    return optional_settings
    def fillup_optional_settings(self, key, func):
        """
        Function to populate the 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.
        """
        present_in_annot = in_annot(func, key)

        if present_in_annot:
            self.diff_bool_others(key, present_in_annot)
        else:
            self.diff_bool_others_default(key, get_default_args(func)[key])
    def __init__(self, bear):
        """
        :param bear:
            A bear class object.
        """
        self.bear = bear
        function = bear.create_arguments if ('create_arguments'
                                             in dir(bear)) else bear.run
        function_name = 'create_arguments' if ('create_arguments'
                                               in dir(bear)) else 'run'
        non_optional_settings = bear.get_non_optional_settings()

        # Get the actual function if the function is decorated.
        original_function = search_for_orig(function, function_name)
        if original_function is not None:
            function = original_function

        optional_settings = get_default_args(function)
        self.create_setting_types_obj(optional_settings, non_optional_settings,
                                      function, function_name, bear)
 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)