def test_extension(self): """Test whether file extensions are identified""" self.assertEqual(GraalRepository.extension('setup.py'), 'py') self.assertEqual(GraalRepository.extension('tests/requirements.txt'), 'txt') self.assertEqual(GraalRepository.extension('LICENSE'), 'LICENSE')
def analyze(self, file_path): """Analyze the content of a file using CLOC and Lizard :param file_path: file path :returns a dict containing the results of the analysis, like the one below { 'blanks': .., 'comments': .., 'loc': .., 'ccn': .., 'avg_ccn': .., 'avg_loc': .., 'avg_tokens': .., 'funs': .., 'tokens': .., 'funs_data': [..] } """ kwargs = {'file_path': file_path} cloc_analysis = self.cloc.analyze(**kwargs) if GraalRepository.extension(file_path) not in self.ALLOWED_EXTENSIONS: return cloc_analysis kwargs['details'] = self.details lizard_analysis = self.lizard.analyze(**kwargs) # the LOC returned by CLOC is replaced by the one obtained with Lizard # for consistency purposes lizard_analysis['blanks'] = cloc_analysis['blanks'] lizard_analysis['comments'] = cloc_analysis['comments'] return lizard_analysis
def analyze(self, **kwargs): """Add information using SCC :param file_path: file path :param repository_level: set to True if analysis has to be performed on a repository :returns result: dict of the results of the analysis """ repository_level = kwargs.get('repository_level', False) if repository_level: file_path = kwargs['repository_path'] else: file_path = kwargs['file_path'] try: scc_command = ['scc', file_path] message = subprocess.check_output(scc_command).decode("utf-8") except subprocess.CalledProcessError as e: message = e.output.decode("utf-8") finally: subprocess._cleanup() if repository_level: results = self.__analyze_repository(message) else: results = self.__analyze_file(message) results['ext'] = GraalRepository.extension(file_path) return results
def analyze(self, **kwargs): """Add information using CLOC :param file_path: file path :param repository_level: set to True if analysis has to be performed on a repository :returns result: dict of the results of the analysis """ file_path = kwargs['file_path'] repository_level = kwargs.get('repository_level', False) try: message = subprocess.check_output(['cloc', file_path]).decode("utf-8") except subprocess.CalledProcessError as e: raise GraalError(cause="Cloc failed at %s, %s" % (file_path, e.output.decode("utf-8"))) finally: subprocess._cleanup() if repository_level: results = self.__analyze_repository(message) else: results = self.__analyze_file(message) results['ext'] = GraalRepository.extension(file_path) return results