Beispiel #1
0
    def load_tests(self, filter=None):
        '''Loads all tests in the plugins directory into testsdictionary.'''
        self.tests = dict()

        extmgr = self._get_extension_manager()

        for plugin in extmgr.plugins:
            fn_name = plugin.name
            function = plugin.plugin
            if hasattr(function, '_checks'):
                for check in function._checks:
                    # if check type hasn't been encountered
                    # yet, initialize to empty dictionary
                    if check not in self.tests:
                        self.tests[check] = {}
                    # if there is a test name collision, bail
                    if fn_name in self.tests[check]:
                        path1 = (utils.get_path_for_function(function)
                                 or '(unknown)')
                        path2 = utils.get_path_for_function(
                            self.tests[check][fn_name]) or '(unknown)'
                        logger.error(
                            "Duplicate function definition "
                            "%s in %s and %s", fn_name, path1, path2)
                        sys.exit(2)
                    else:
                        self.tests[check][fn_name] = function
                        logger.debug('added function %s targetting %s',
                                     fn_name, check)
        self._filter_tests(filter)
    def load_tests(self, filter=None):
        '''Loads all tests in the plugins directory into testsdictionary.'''
        self.tests = dict()

        extmgr = self._get_extension_manager()

        for plugin in extmgr.plugins:
            fn_name = plugin.name
            function = plugin.plugin
            if hasattr(function, '_checks'):
                for check in function._checks:
                    # if check type hasn't been encountered
                    # yet, initialize to empty dictionary
                    if check not in self.tests:
                        self.tests[check] = {}
                    # if there is a test name collision, bail
                    if fn_name in self.tests[check]:
                        path1 = (utils.get_path_for_function(function) or
                                 '(unknown)')
                        path2 = utils.get_path_for_function(
                            self.tests[check][fn_name]) or '(unknown)'
                        logger.error(
                            "Duplicate function definition "
                            "%s in %s and %s", fn_name, path1, path2
                            )
                        sys.exit(2)
                    else:
                        self.tests[check][fn_name] = function
                        logger.debug(
                            'added function %s targetting %s',
                            fn_name, check
                            )
        self._filter_tests(filter)
Beispiel #3
0
    def load_tests(self, filter=None):
        '''Loads all tests in the plugins directory into tests dictionary.'''
        self.tests = dict()

        extmgr = self._get_extension_manager()

        for plugin in extmgr.plugins:
            fn_name = plugin.name
            function = plugin.plugin
            if hasattr(function, '_takes_config'):
                test_config = self.config.get_option(function._takes_config)
                if test_config is None:
                    genner = importlib.import_module(function.__module__)
                    if hasattr(genner, 'gen_config'):
                        test_config = genner.gen_config(function._takes_config)
                if test_config is None:
                    warnings.warn(
                        '"{0}" has been skipped due to missing config '
                        '"{1}".'.format(function.__name__,
                                        function._takes_config))
                    continue
                else:
                    setattr(function, "_config", test_config)

            if hasattr(function, '_checks'):
                for check in function._checks:
                    # if check type hasn't been encountered
                    # yet, initialize to empty dictionary
                    if check not in self.tests:
                        self.tests[check] = {}
                    # if there is a test name collision, bail
                    if fn_name in self.tests[check]:
                        path1 = (utils.get_path_for_function(function) or
                                 '(unknown)')
                        path2 = utils.get_path_for_function(
                            self.tests[check][fn_name]) or '(unknown)'
                        logger.error(
                            "Duplicate function definition "
                            "%s in %s and %s", fn_name, path1, path2
                            )
                        sys.exit(2)
                    else:
                        self.tests[check][fn_name] = function
                        logger.debug(
                            'added function %s targetting %s',
                            fn_name, check
                            )
        self._filter_tests(filter)
Beispiel #4
0
 def test_path_for_function_no_module(self):
     self.assertIsNone(b_utils.get_path_for_function(1))
Beispiel #5
0
 def test_path_for_function_no_file(self):
     self.assertIsNone(b_utils.get_path_for_function(sys.settrace))
Beispiel #6
0
 def test_path_for_function(self):
     path = b_utils.get_path_for_function(b_utils.get_path_for_function)
     self.assertEqual(path, b_utils.__file__)
Beispiel #7
0
 def test_path_for_function_no_module(self):
     self.assertIsNone(b_utils.get_path_for_function(1))
Beispiel #8
0
 def test_path_for_function_no_file(self):
     self.assertIsNone(b_utils.get_path_for_function(sys.settrace))
Beispiel #9
0
 def test_path_for_function(self):
     path = b_utils.get_path_for_function(b_utils.get_path_for_function)
     self.assertEqual(path, b_utils.__file__)