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 ):
@@ -159,6 +161,27 @@ 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
+
162
185
def test_metadata_category (self ):
163
186
"""Test metadata_category"""
164
187
@@ -186,6 +209,18 @@ def test_metadata_category(self):
186
209
}
187
210
self .assertEqual (CoLic .metadata_category (item ), CATEGORY_COLIC_NOMOS )
188
211
212
+ item = {
213
+ "Author" :
"Valerio Cosentino <[email protected] >" ,
214
+ "AuthorDate" : "Fri May 18 18:26:48 2018 +0200" ,
215
+ "Commit" :
"Valerio Cosentino <[email protected] >" ,
216
+ "CommitDate" : "Fri May 18 18:26:48 2018 +0200" ,
217
+ "analysis" : [],
218
+ "analyzer" : "scancode_cli" ,
219
+ "commit" : "075f0c6161db5a3b1c8eca45e08b88469bb148b9" ,
220
+ "message" : "[perceval] first commit"
221
+ }
222
+ self .assertEqual (CoLic .metadata_category (item ), CATEGORY_COLIC_SCANCODE_CLI )
223
+
189
224
item = {
190
225
"Author" :
"Valerio Cosentino <[email protected] >" ,
191
226
"AuthorDate" : "Fri May 18 18:26:48 2018 +0200" ,
@@ -218,6 +253,10 @@ def test_init(self):
218
253
self .assertIsInstance (license_analyzer , LicenseAnalyzer )
219
254
self .assertIsInstance (license_analyzer .analyzer , ScanCode )
220
255
256
+ license_analyzer = LicenseAnalyzer (SCANCODE_CLI_PATH , SCANCODE_CLI )
257
+ self .assertIsInstance (license_analyzer , LicenseAnalyzer )
258
+ self .assertIsInstance (license_analyzer .analyzer , ScanCode )
259
+
221
260
with self .assertRaises (GraalError ):
222
261
_ = LicenseAnalyzer ("/tmp/analyzer" , SCANCODE )
223
262
@@ -236,6 +275,12 @@ def test_analyze(self):
236
275
237
276
self .assertIn ('licenses' , analysis )
238
277
278
+ file_paths = [os .path .join (self .tmp_data_path , ANALYZER_TEST_FILE )]
279
+ license_analyzer = LicenseAnalyzer (SCANCODE_CLI_PATH , kind = SCANCODE_CLI )
280
+ analysis = license_analyzer .analyze (file_paths )
281
+
282
+ self .assertIn ('licenses' , analysis )
283
+
239
284
240
285
class TestCoLicCommand (unittest .TestCase ):
241
286
"""CoLicCommand tests"""
0 commit comments