def test_fetch_scancode_cli(self): """Test whether commits are properly processed""" cl = CoLic('http://example.com', self.git_path, self.worktree_path, exec_path=SCANCODE_CLI_PATH, in_paths=['perceval/backends/core/github.py']) commits = [ commit for commit in cl.fetch(category=CATEGORY_COLIC_SCANCODE_CLI) ] self.assertEqual(len(commits), 1) self.assertFalse(os.path.exists(cl.worktreepath)) commit = commits[0] self.assertEqual(commit['backend_name'], 'CoLic') self.assertEqual(commit['category'], CATEGORY_COLIC_SCANCODE_CLI) self.assertEqual(commit['data']['analysis'][0]['file_path'], 'perceval/backends/core/github.py') self.assertTrue('Author' in commit['data']) self.assertTrue('Commit' in commit['data']) self.assertFalse('files' in commit['data']) self.assertFalse('parents' in commit['data']) self.assertFalse('refs' in commit['data'])
def test_initialization(self): """Test whether attributes are initializated""" cl = CoLic('http://example.com', self.git_path, NOMOS_PATH, self.worktree_path, tag='test') self.assertEqual(cl.uri, 'http://example.com') self.assertEqual(cl.gitpath, self.git_path) self.assertEqual( cl.worktreepath, os.path.join(self.worktree_path, os.path.split(cl.gitpath)[1])) self.assertEqual(cl.origin, 'http://example.com') self.assertEqual(cl.tag, 'test') self.assertEqual(cl.exec_path, NOMOS_PATH) self.assertIsNone(cl.analyzer) self.assertIsNone(cl.analyzer_kind) cl = CoLic('http://example.com', self.git_path, NOMOS_PATH, self.worktree_path, tag='test') self.assertEqual(cl.uri, 'http://example.com') self.assertEqual(cl.gitpath, self.git_path) self.assertEqual( cl.worktreepath, os.path.join(self.worktree_path, os.path.split(cl.gitpath)[1])) self.assertEqual(cl.origin, 'http://example.com') self.assertEqual(cl.tag, 'test') self.assertEqual(cl.exec_path, NOMOS_PATH) self.assertIsNone(cl.analyzer) self.assertIsNone(cl.analyzer_kind) # When tag is empty or None it will be set to the value in uri cl = CoLic('http://example.com', self.git_path, NOMOS_PATH, self.worktree_path) self.assertEqual(cl.origin, 'http://example.com') self.assertEqual(cl.tag, 'http://example.com') self.assertEqual(cl.exec_path, NOMOS_PATH) self.assertIsNone(cl.analyzer) self.assertIsNone(cl.analyzer_kind) cl = CoLic('http://example.com', self.git_path, NOMOS_PATH, self.worktree_path) self.assertEqual(cl.origin, 'http://example.com') self.assertEqual(cl.tag, 'http://example.com') self.assertEqual(cl.exec_path, NOMOS_PATH) self.assertIsNone(cl.analyzer) self.assertIsNone(cl.analyzer_kind) with self.assertRaises(GraalError): _ = CoLic('http://example.com', self.git_path, "/tmp/invalid", worktreepath=self.worktree_path)
def test_fetch_unknown(self): """Test whether commits are properly processed""" cl = CoLic('http://example.com', self.git_path, SCANCODE_CLI_PATH, self.worktree_path, in_paths=['perceval/backends/core/github.py']) with self.assertRaises(GraalError): _ = cl.fetch(category="unknown")
def test_metadata_category(self): """Test metadata_category""" item = { "Author": "Valerio Cosentino <*****@*****.**>", "AuthorDate": "Fri May 18 18:26:48 2018 +0200", "Commit": "Valerio Cosentino <*****@*****.**>", "CommitDate": "Fri May 18 18:26:48 2018 +0200", "analysis": [], "analyzer": "scancode", "commit": "075f0c6161db5a3b1c8eca45e08b88469bb148b9", "message": "[perceval] first commit" } self.assertEqual(CoLic.metadata_category(item), CATEGORY_COLIC_SCANCODE) item = { "Author": "Valerio Cosentino <*****@*****.**>", "AuthorDate": "Fri May 18 18:26:48 2018 +0200", "Commit": "Valerio Cosentino <*****@*****.**>", "CommitDate": "Fri May 18 18:26:48 2018 +0200", "analysis": [], "analyzer": "nomos", "commit": "075f0c6161db5a3b1c8eca45e08b88469bb148b9", "message": "[perceval] first commit" } self.assertEqual(CoLic.metadata_category(item), CATEGORY_COLIC_NOMOS) item = { "Author": "Valerio Cosentino <*****@*****.**>", "AuthorDate": "Fri May 18 18:26:48 2018 +0200", "Commit": "Valerio Cosentino <*****@*****.**>", "CommitDate": "Fri May 18 18:26:48 2018 +0200", "analysis": [], "analyzer": "scancode_cli", "commit": "075f0c6161db5a3b1c8eca45e08b88469bb148b9", "message": "[perceval] first commit" } self.assertEqual(CoLic.metadata_category(item), CATEGORY_COLIC_SCANCODE_CLI) item = { "Author": "Valerio Cosentino <*****@*****.**>", "AuthorDate": "Fri May 18 18:26:48 2018 +0200", "Commit": "Valerio Cosentino <*****@*****.**>", "CommitDate": "Fri May 18 18:26:48 2018 +0200", "analysis": [], "analyzer": "unknown", "commit": "075f0c6161db5a3b1c8eca45e08b88469bb148b9", "message": "[perceval] first commit" } with self.assertRaises(GraalError): _ = CoLic.metadata_category(item)
def test_fetch_empty_in_paths(self): """Test whether all commits are processed when the no `in_paths` are provided""" cl = CoLic('http://example.com', self.git_path, NOMOS_PATH, self.worktree_path, in_paths=[]) commits = [commit for commit in cl.fetch(category=CATEGORY_COLIC_NOMOS)] self.assertEqual(len(commits), 6) for commit in commits: self.assertEqual(commit['backend_name'], 'CoLic') self.assertEqual(commit['category'], CATEGORY_COLIC_NOMOS) self.assertIn('analysis', commit['data']) self.assertTrue('Author' in commit['data']) self.assertTrue('Commit' in commit['data']) self.assertFalse('files' in commit['data']) self.assertFalse('parents' in commit['data']) self.assertFalse('refs' in commit['data'])
# GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Author: # Sumit Kumar Jangir <*****@*****.**> # imports from graal.backends.core.colic import CoLic, CATEGORY_COLIC_NOMOS, CATEGORY_COLIC_SCANCODE from graal.graal import GraalCommand # setting graal argument parser parser = GraalCommand.setup_cmd_parser() arg = [ 'https://github.com/sumitskj/Prajawalan2019.git', '--git-path', '/tmp/clone' ] args = parser.parse(*arg) # nomos exec_path exec_path = '/home/sumit/fossology/src/nomos/agent/nomossa' # Colic object initialization cc = CoLic(uri=args.uri, git_path=args.git_path, exec_path=exec_path) # fetch all commits for com in cc.fetch(): print(com['data']['CommitDate'])
#! /usr/bin/env python3 from graal.backends.core.cocom import CoCom from graal.backends.core.colic import CoLic SCANCODE = 'scancode' CATEGORY_COLIC_SCANCODE = 'code_license_' + SCANCODE # URL for the git repo to analyze repo_uri = 'https://github.com/chaoss/grimoirelab-toolkit' # directory where to mirror the repo repo_dir = 'users/tanxin/github/graal-cocom' # Cocom object initialization cc = CoCom(uri=repo_uri, git_path=repo_dir) # CoLic object initialization cl = CoLic(uri=repo_uri, git_path=repo_dir, exec_path='/Users/tanxin/Downloads/scancode-toolkit-3.0.2/scancode') # fetch all commits and try Cocom for commit in cc.fetch(): print(commit) ### # fetch all commits and try scancode for commit in cl.fetch(category=CATEGORY_COLIC_SCANCODE): print(commit) ###