def test_files(self): """Test whether all files in a directory and its sub-directories are shown""" new_path = os.path.join(self.tmp_path, 'testworktree') repo = GraalRepository('http://example.git', self.git_path) repo.worktree(new_path) expected = [ os.path.join(new_path, 'perceval/archive.py'), os.path.join(new_path, 'perceval/backend.py'), os.path.join(new_path, 'perceval/client.py'), os.path.join(new_path, 'perceval/__init__.py'), os.path.join(new_path, 'perceval/_version.py'), os.path.join(new_path, 'perceval/utils.py'), os.path.join(new_path, 'perceval/errors.py'), os.path.join(new_path, 'perceval/backends/__init__.py'), os.path.join(new_path, 'perceval/backends/core/__init__.py'), os.path.join(new_path, 'perceval/backends/core/github.py'), os.path.join(new_path, 'perceval/backends/core/mbox.py'), os.path.join(new_path, 'perceval/backends/core/git.py') ] files = repo.files(new_path) self.assertEqual(len(files), len(expected)) for f in files: self.assertIn(f, expected) repo.prune() self.assertFalse(os.path.exists(repo.worktreepath))
def _post(self, commit): """Remove attributes of the Graal item obtained :param commit: a Graal commit item """ commit['files'] = [ f.replace(self.worktreepath + '/', '') for f in GraalRepository.files(self.worktreepath) ] commit.pop('refs', None) commit['analyzer'] = self.analyzer_kind return commit
def _analyze(self, commit): """Analyse a commit and the corresponding checkout version of the repository :param commit: a Perceval commit item """ files = GraalRepository.files(self.worktreepath) analysis = [] for file_path in files: if self.in_paths: found = [p for p in self.in_paths if file_path.endswith(p)] if not found: continue file_info = self.file_analyzer.analyze(file_path) file_info.update({'file_path': file_path.replace(self.worktreepath + '/', "")}) analysis.append(file_info) return analysis
def test_files_no_dir(self): """Test whether an empty list is returned when the input is none""" repo = GraalRepository('http://example.git', self.git_path) files = repo.files(None) self.assertEqual(files, [])