33
33
from graal .backends .core .analyzers .scancode import ScanCode
34
34
from graal .backends .core .colic import (CATEGORY_COLIC_NOMOS ,
35
35
CATEGORY_COLIC_SCANCODE ,
36
+ CATEGORY_COLIC_SCANCODE_CLI ,
36
37
NOMOS ,
37
38
SCANCODE ,
39
+ SCANCODE_CLI ,
38
40
CoLic ,
39
41
LicenseAnalyzer ,
40
42
CoLicCommand )
41
43
from perceval .utils import DEFAULT_DATETIME
42
44
from test_graal import TestCaseGraal
43
45
from base_analyzer import (ANALYZER_TEST_FILE ,
44
46
TestCaseAnalyzer )
45
- from utils import NOMOS_PATH , SCANCODE_PATH
47
+ from utils import NOMOS_PATH , SCANCODE_PATH , SCANCODE_CLI_PATH
46
48
47
49
48
50
class TestCoLicBackend (TestCaseGraal ):
@@ -122,7 +124,7 @@ def test_fetch_nomossa(self):
122
124
123
125
cl = CoLic ('http://example.com' , self .git_path , NOMOS_PATH , self .worktree_path ,
124
126
in_paths = ['perceval/backends/core/github.py' ])
125
- commits = [commit for commit in cl .fetch ()]
127
+ commits = [commit for commit in cl .fetch (category = CATEGORY_COLIC_NOMOS )]
126
128
127
129
self .assertEqual (len (commits ), 1 )
128
130
self .assertFalse (os .path .exists (cl .worktreepath ))
@@ -159,6 +161,36 @@ def test_fetch_scancode(self):
159
161
self .assertFalse ('parents' in commit ['data' ])
160
162
self .assertFalse ('refs' in commit ['data' ])
161
163
164
+ def test_fetch_scancode_cli (self ):
165
+ """Test whether commits are properly processed"""
166
+
167
+ cl = CoLic ('http://example.com' , self .git_path , SCANCODE_CLI_PATH , self .worktree_path ,
168
+ in_paths = ['perceval/backends/core/github.py' ])
169
+ commits = [commit for commit in cl .fetch (category = CATEGORY_COLIC_SCANCODE_CLI )]
170
+
171
+ self .assertEqual (len (commits ), 1 )
172
+ self .assertFalse (os .path .exists (cl .worktreepath ))
173
+
174
+ for commit in commits :
175
+ self .assertEqual (commit ['backend_name' ], 'CoLic' )
176
+ self .assertEqual (commit ['category' ], CATEGORY_COLIC_SCANCODE_CLI )
177
+ self .assertEqual (commit ['data' ]['analysis' ]['files' ][0 ]['file_path' ],
178
+ 'perceval/backends/core/github.py' )
179
+ self .assertTrue ('Author' in commit ['data' ])
180
+ self .assertTrue ('Commit' in commit ['data' ])
181
+ self .assertFalse ('files' in commit ['data' ])
182
+ self .assertFalse ('parents' in commit ['data' ])
183
+ self .assertFalse ('refs' in commit ['data' ])
184
+
185
+ def test_fetch_unknown (self ):
186
+ """Test whether commits are properly processed"""
187
+
188
+ cl = CoLic ('http://example.com' , self .git_path , SCANCODE_CLI_PATH , self .worktree_path ,
189
+ in_paths = ['perceval/backends/core/github.py' ])
190
+
191
+ with self .assertRaises (GraalError ):
192
+ _ = cl .fetch (category = "unknown" )
193
+
162
194
def test_metadata_category (self ):
163
195
"""Test metadata_category"""
164
196
@@ -186,6 +218,18 @@ def test_metadata_category(self):
186
218
}
187
219
self .assertEqual (CoLic .metadata_category (item ), CATEGORY_COLIC_NOMOS )
188
220
221
+ item = {
222
+ "Author" :
"Valerio Cosentino <[email protected] >" ,
223
+ "AuthorDate" : "Fri May 18 18:26:48 2018 +0200" ,
224
+ "Commit" :
"Valerio Cosentino <[email protected] >" ,
225
+ "CommitDate" : "Fri May 18 18:26:48 2018 +0200" ,
226
+ "analysis" : [],
227
+ "analyzer" : "scancode_cli" ,
228
+ "commit" : "075f0c6161db5a3b1c8eca45e08b88469bb148b9" ,
229
+ "message" : "[perceval] first commit"
230
+ }
231
+ self .assertEqual (CoLic .metadata_category (item ), CATEGORY_COLIC_SCANCODE_CLI )
232
+
189
233
item = {
190
234
"Author" :
"Valerio Cosentino <[email protected] >" ,
191
235
"AuthorDate" : "Fri May 18 18:26:48 2018 +0200" ,
@@ -218,6 +262,10 @@ def test_init(self):
218
262
self .assertIsInstance (license_analyzer , LicenseAnalyzer )
219
263
self .assertIsInstance (license_analyzer .analyzer , ScanCode )
220
264
265
+ license_analyzer = LicenseAnalyzer (SCANCODE_CLI_PATH , SCANCODE_CLI )
266
+ self .assertIsInstance (license_analyzer , LicenseAnalyzer )
267
+ self .assertIsInstance (license_analyzer .analyzer , ScanCode )
268
+
221
269
with self .assertRaises (GraalError ):
222
270
_ = LicenseAnalyzer ("/tmp/analyzer" , SCANCODE )
223
271
@@ -236,6 +284,12 @@ def test_analyze(self):
236
284
237
285
self .assertIn ('licenses' , analysis )
238
286
287
+ file_paths = [os .path .join (self .tmp_data_path , ANALYZER_TEST_FILE )]
288
+ license_analyzer = LicenseAnalyzer (SCANCODE_CLI_PATH , kind = SCANCODE_CLI )
289
+ analysis = license_analyzer .analyze (file_paths )
290
+
291
+ self .assertIn ('licenses' , analysis ['files' ][0 ])
292
+
239
293
240
294
class TestCoLicCommand (unittest .TestCase ):
241
295
"""CoLicCommand tests"""
0 commit comments