Skip to content

Commit 3382cb4

Browse files
committed
[analyzer] Fix results for deleted files and alter tests
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 <[email protected]>
1 parent 5dc57fa commit 3382cb4

File tree

8 files changed

+60
-14
lines changed

8 files changed

+60
-14
lines changed

graal/backends/core/cocom.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class CoCom(Graal):
7070
:raises RepositoryError: raised when there was an error cloning or
7171
updating the repository.
7272
"""
73-
version = '0.2.3'
73+
version = '0.2.4'
7474

7575
CATEGORIES = [CATEGORY_COCOM]
7676

@@ -137,7 +137,30 @@ def _analyze(self, commit):
137137

138138
local_path = self.worktreepath + '/' + file_path
139139
if not GraalRepository.exists(local_path):
140-
continue
140+
file_info = {
141+
'blanks': None,
142+
'comments': None,
143+
'loc': None,
144+
'ccn': None,
145+
'avg_ccn': None,
146+
'avg_loc': None,
147+
'avg_tokens': None,
148+
'num_funs': None,
149+
'tokens': None,
150+
'file_path': file_path,
151+
}
152+
if self.details:
153+
file_info['funs'] = []
154+
155+
if committed_file.get("newfile", None):
156+
file_path = committed_file["newfile"]
157+
local_path = self.worktreepath + '/' + file_path
158+
analysis.append(file_info)
159+
elif committed_file.get("action", None) == "D":
160+
analysis.append(file_info)
161+
continue
162+
else:
163+
continue
141164

142165
file_info = self.file_analyzer.analyze(local_path)
143166
file_info.update({'file_path': file_path})
@@ -182,9 +205,9 @@ def analyze(self, file_path):
182205
'avg_ccn': ..,
183206
'avg_loc': ..,
184207
'avg_tokens': ..,
185-
'funs': ..,
208+
'num_funs': ..,
186209
'tokens': ..,
187-
'funs_data': [..]
210+
'funs': [..]
188211
}
189212
"""
190213
kwargs = {'file_path': file_path}

tests/data/graaltest.zip

32 Bytes
Binary file not shown.

tests/test_cocom.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,29 @@ def test_fetch(self):
119119
self.assertFalse('parents' in commit['data'])
120120
self.assertFalse('refs' in commit['data'])
121121

122+
def test_fetch_analysis(self):
123+
"""Test whether commits have properly set values"""
124+
125+
cc = CoCom('http://example.com', self.git_path, self.worktree_path)
126+
commits = [commit for commit in cc.fetch()]
127+
128+
self.assertEqual(len(commits), 6)
129+
self.assertFalse(os.path.exists(cc.worktreepath))
130+
131+
deleted_file_commit = commits[5]
132+
133+
self.assertEqual(deleted_file_commit['data']['analysis'][0]['file_path'],
134+
'perceval/backends/graal.py')
135+
self.assertEqual(deleted_file_commit['data']['analysis'][0]['blanks'], None)
136+
self.assertEqual(deleted_file_commit['data']['analysis'][0]['comments'], None)
137+
self.assertEqual(deleted_file_commit['data']['analysis'][0]['loc'], None)
138+
self.assertEqual(deleted_file_commit['data']['analysis'][0]['ccn'], None)
139+
self.assertEqual(deleted_file_commit['data']['analysis'][0]['avg_ccn'], None)
140+
self.assertEqual(deleted_file_commit['data']['analysis'][0]['avg_loc'], None)
141+
self.assertEqual(deleted_file_commit['data']['analysis'][0]['avg_tokens'], None)
142+
self.assertEqual(deleted_file_commit['data']['analysis'][0]['num_funs'], None)
143+
self.assertEqual(deleted_file_commit['data']['analysis'][0]['tokens'], None)
144+
122145

123146
class TestFileAnalyzer(TestCaseAnalyzer):
124147
"""FileAnalyzer tests"""

tests/test_codep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_fetch(self):
9090
cd = CoDep('http://example.com', self.git_path, self.worktree_path, entrypoint="perceval")
9191
commits = [commit for commit in cd.fetch()]
9292

93-
self.assertEqual(len(commits), 3)
93+
self.assertEqual(len(commits), 6)
9494
self.assertFalse(os.path.exists(cd.worktreepath))
9595

9696
commit = commits[0]

tests/test_colang.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_fetch_linguist(self):
9191
cl = CoLang('http://example.com', self.git_path, tag="test")
9292
commits = [commit for commit in cl.fetch()]
9393

94-
self.assertEqual(len(commits), 3)
94+
self.assertEqual(len(commits), 6)
9595
self.assertFalse(os.path.exists(cl.worktreepath))
9696

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

109-
self.assertEqual(len(commits), 3)
109+
self.assertEqual(len(commits), 6)
110110
self.assertFalse(os.path.exists(cl.worktreepath))
111111

112112
commit = commits[0]

tests/test_coqua.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_fetch_pylint(self):
9898
self.worktree_path, entrypoint="perceval")
9999
commits = [commit for commit in cq.fetch()]
100100

101-
self.assertEqual(len(commits), 3)
101+
self.assertEqual(len(commits), 6)
102102
self.assertFalse(os.path.exists(cq.worktreepath))
103103

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

124-
self.assertEqual(len(commits), 3)
124+
self.assertEqual(len(commits), 6)
125125
self.assertFalse(os.path.exists(cq.worktreepath))
126126

127127
commit = commits[0]

tests/test_covuln.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_fetch(self):
9090
cd = CoVuln('http://example.com', self.git_path, self.worktree_path, entrypoint="perceval")
9191
commits = [commit for commit in cd.fetch()]
9292

93-
self.assertEqual(len(commits), 3)
93+
self.assertEqual(len(commits), 6)
9494
self.assertFalse(os.path.exists(cd.worktreepath))
9595

9696
commit = commits[0]

tests/test_graal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def test_fetch_no_analysis(self):
247247
graal = Graal('http://example.com', self.git_path, self.worktree_path)
248248
commits = [commit for commit in graal.fetch()]
249249

250-
self.assertEqual(len(commits), 3)
250+
self.assertEqual(len(commits), 6)
251251
self.assertFalse(os.path.exists(graal.worktreepath))
252252

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

264-
self.assertEqual(len(commits), 3)
264+
self.assertEqual(len(commits), 6)
265265
self.assertFalse(os.path.exists(mocked.worktreepath))
266266

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

765-
self.assertEqual(len(items), 3)
765+
self.assertEqual(len(items), 6)
766766
for i in items:
767767
self.assertEqual(i['category'], CATEGORY_MOCKED)
768768

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

781-
self.assertEqual(len(items), 3)
781+
self.assertEqual(len(items), 6)
782782
for i in items:
783783
self.assertEqual(i['category'], CATEGORY_MOCKED)
784784

0 commit comments

Comments
 (0)