Beispiel #1
0
    def test_get_files(self):
        # Arrange
        path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), os.pardir, 'attributes',
                         'license'))
        expected = [os.path.join(path, 'main.py')]

        # Act
        actual = utilities.get_files(path, language='Python')

        # Assert
        self.assertCountEqual(expected, actual)
Beispiel #2
0
    def test_get_files(self):
        # Arrange
        path = os.path.abspath(
            os.path.join(
                os.path.dirname(__file__), os.pardir, 'attributes', 'license'
            )
        )
        expected = [os.path.join(path, 'main.py')]

        # Act
        actual = utilities.get_files(path, language='Python')

        # Assert
        self.assertCountEqual(expected, actual)
Beispiel #3
0
    def discover(self, path):
        if not (self.frameworks and self.languages and self.extensions):
            raise Exception(
                '{0} is not appropriately configured.'.format(
                    self.__class__.__name__
                )
            )

        # SLOC of source code
        _sloc = utilities.get_loc(path)
        sloc = 0
        for language in self.languages:
            if language in _sloc:
                sloc += _sloc[language]['sloc']

        proportion = 0
        if sloc > 0:
            # Pass 1: Look for a unit testing frameworks
            for framework in self.frameworks:
                proportion += framework(path, sloc)

            # Pass 2: Look for files in conventional test directories
            # NOTE: Second pass is necessary only when the proportion of unit
            # tests from Pass 1 is less than 1%
            if proportion < 0.01:
                _path = None
                done = False
                for (root, dnames, _) in os.walk(path):
                    for item in TEST_DIRECTORIES:
                        if item in dnames:
                            _path = os.path.join(root, item)
                            done = True
                            break
                    if done:
                        break

                files = None
                if _path:
                    files = utilities.get_files(_path, self.language)
                    if files:
                        # SLOC of test code
                        print('path_init: ',path)
                        _slotc = utilities.get_loc(path, files=files)
                        slotc = 0
                        for language in self.languages:
                            if language in _slotc:
                                slotc += _slotc[language]['sloc']
                        proportion = max(proportion, slotc / sloc)

        return proportion
Beispiel #4
0
    def discover(self, path):
        if not (self.frameworks and self.languages and self.extensions):
            raise Exception("{0} is not appropriately configured.".format(self.__class__.__name__))

        # SLOC of source code
        _sloc = utilities.get_loc(path)
        sloc = 0
        for language in self.languages:
            if language in _sloc:
                sloc += _sloc[language]["sloc"]

        proportion = 0
        if sloc > 0:
            # Pass 1: Look for a unit testing frameworks
            for framework in self.frameworks:
                proportion += framework(path, sloc)

            # Pass 2: Look for files in conventional test directories
            # NOTE: Second pass is necessary only when the proportion of unit
            # tests from Pass 1 is less than 1%
            if proportion < 0.01:
                _path = None
                done = False
                for (root, dnames, _) in os.walk(path):
                    for item in TEST_DIRECTORIES:
                        if item in dnames:
                            _path = os.path.join(root, item)
                            done = True
                            break
                    if done:
                        break

                files = None
                if _path:
                    files = utilities.get_files(_path, self.language)
                    if files:
                        # SLOC of test code
                        _slotc = utilities.get_loc(path, files=files)
                        slotc = 0
                        for language in self.languages:
                            if language in _slotc:
                                slotc += _slotc[language]["sloc"]
                        proportion = max(proportion, slotc / sloc)

        return proportion