Skip to content

Commit

Permalink
[analyzer] Fix results for deleted files and alter tests
Browse files Browse the repository at this point in the history
There can be two scenarios, a deleted file and other renamed (or the one
which has changed the directory). These changes handles both the cases.
Alter test data to accomodate cases for deleted files results

Signed-off-by: inishchith <inishchith@gmail.com>
  • Loading branch information
inishchith committed Jun 13, 2019
1 parent 5dc57fa commit 3382cb4
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 14 deletions.
31 changes: 27 additions & 4 deletions graal/backends/core/cocom.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class CoCom(Graal):
:raises RepositoryError: raised when there was an error cloning or
updating the repository.
"""
version = '0.2.3'
version = '0.2.4'

CATEGORIES = [CATEGORY_COCOM]

Expand Down Expand Up @@ -137,7 +137,30 @@ def _analyze(self, commit):

local_path = self.worktreepath + '/' + file_path
if not GraalRepository.exists(local_path):
continue
file_info = {
'blanks': None,
'comments': None,
'loc': None,
'ccn': None,
'avg_ccn': None,
'avg_loc': None,
'avg_tokens': None,
'num_funs': None,
'tokens': None,
'file_path': file_path,
}
if self.details:
file_info['funs'] = []

if committed_file.get("newfile", None):
file_path = committed_file["newfile"]
local_path = self.worktreepath + '/' + file_path
analysis.append(file_info)
elif committed_file.get("action", None) == "D":
analysis.append(file_info)
continue
else:
continue

file_info = self.file_analyzer.analyze(local_path)
file_info.update({'file_path': file_path})
Expand Down Expand Up @@ -182,9 +205,9 @@ def analyze(self, file_path):
'avg_ccn': ..,
'avg_loc': ..,
'avg_tokens': ..,
'funs': ..,
'num_funs': ..,
'tokens': ..,
'funs_data': [..]
'funs': [..]
}
"""
kwargs = {'file_path': file_path}
Expand Down
Binary file modified tests/data/graaltest.zip
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/test_cocom.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,29 @@ def test_fetch(self):
self.assertFalse('parents' in commit['data'])
self.assertFalse('refs' in commit['data'])

def test_fetch_analysis(self):
"""Test whether commits have properly set values"""

cc = CoCom('http://example.com', self.git_path, self.worktree_path)
commits = [commit for commit in cc.fetch()]

self.assertEqual(len(commits), 6)
self.assertFalse(os.path.exists(cc.worktreepath))

deleted_file_commit = commits[5]

self.assertEqual(deleted_file_commit['data']['analysis'][0]['file_path'],
'perceval/backends/graal.py')
self.assertEqual(deleted_file_commit['data']['analysis'][0]['blanks'], None)
self.assertEqual(deleted_file_commit['data']['analysis'][0]['comments'], None)
self.assertEqual(deleted_file_commit['data']['analysis'][0]['loc'], None)
self.assertEqual(deleted_file_commit['data']['analysis'][0]['ccn'], None)
self.assertEqual(deleted_file_commit['data']['analysis'][0]['avg_ccn'], None)
self.assertEqual(deleted_file_commit['data']['analysis'][0]['avg_loc'], None)
self.assertEqual(deleted_file_commit['data']['analysis'][0]['avg_tokens'], None)
self.assertEqual(deleted_file_commit['data']['analysis'][0]['num_funs'], None)
self.assertEqual(deleted_file_commit['data']['analysis'][0]['tokens'], None)


class TestFileAnalyzer(TestCaseAnalyzer):
"""FileAnalyzer tests"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_codep.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_fetch(self):
cd = CoDep('http://example.com', self.git_path, self.worktree_path, entrypoint="perceval")
commits = [commit for commit in cd.fetch()]

self.assertEqual(len(commits), 3)
self.assertEqual(len(commits), 6)
self.assertFalse(os.path.exists(cd.worktreepath))

commit = commits[0]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_colang.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_fetch_linguist(self):
cl = CoLang('http://example.com', self.git_path, tag="test")
commits = [commit for commit in cl.fetch()]

self.assertEqual(len(commits), 3)
self.assertEqual(len(commits), 6)
self.assertFalse(os.path.exists(cl.worktreepath))

commit = commits[0]
Expand All @@ -106,7 +106,7 @@ def test_fetch_cloc(self):
cl = CoLang('http://example.com', self.git_path, tag="test")
commits = [commit for commit in cl.fetch(category=CATEGORY_COLANG_CLOC)]

self.assertEqual(len(commits), 3)
self.assertEqual(len(commits), 6)
self.assertFalse(os.path.exists(cl.worktreepath))

commit = commits[0]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_coqua.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_fetch_pylint(self):
self.worktree_path, entrypoint="perceval")
commits = [commit for commit in cq.fetch()]

self.assertEqual(len(commits), 3)
self.assertEqual(len(commits), 6)
self.assertFalse(os.path.exists(cq.worktreepath))

commit = commits[0]
Expand All @@ -121,7 +121,7 @@ def test_fetch_flake8(self):
commits = [commit for commit in cq.fetch(
category=CATEGORY_COQUA_FLAKE8)]

self.assertEqual(len(commits), 3)
self.assertEqual(len(commits), 6)
self.assertFalse(os.path.exists(cq.worktreepath))

commit = commits[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_covuln.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_fetch(self):
cd = CoVuln('http://example.com', self.git_path, self.worktree_path, entrypoint="perceval")
commits = [commit for commit in cd.fetch()]

self.assertEqual(len(commits), 3)
self.assertEqual(len(commits), 6)
self.assertFalse(os.path.exists(cd.worktreepath))

commit = commits[0]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_graal.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_fetch_no_analysis(self):
graal = Graal('http://example.com', self.git_path, self.worktree_path)
commits = [commit for commit in graal.fetch()]

self.assertEqual(len(commits), 3)
self.assertEqual(len(commits), 6)
self.assertFalse(os.path.exists(graal.worktreepath))

for commit in commits:
Expand All @@ -261,7 +261,7 @@ def test_fetch_analysis(self):
mocked = MockedGraal('http://example.com', self.git_path, self.worktree_path)
commits = [commit for commit in mocked.fetch()]

self.assertEqual(len(commits), 3)
self.assertEqual(len(commits), 6)
self.assertFalse(os.path.exists(mocked.worktreepath))

commit = commits[0]
Expand Down Expand Up @@ -762,7 +762,7 @@ def test_items(self):
items = graal.graal.fetch(CommandBackend, args, CATEGORY_MOCKED)
items = [item for item in items]

self.assertEqual(len(items), 3)
self.assertEqual(len(items), 6)
for i in items:
self.assertEqual(i['category'], CATEGORY_MOCKED)

Expand All @@ -778,7 +778,7 @@ def test_items_no_category(self):
items = graal.graal.fetch(CommandBackend, args, None)
items = [item for item in items]

self.assertEqual(len(items), 3)
self.assertEqual(len(items), 6)
for i in items:
self.assertEqual(i['category'], CATEGORY_MOCKED)

Expand Down

0 comments on commit 3382cb4

Please sign in to comment.