2222from attributecode import ERROR
2323from attributecode import INFO
2424from attributecode import CRITICAL
25+ from attributecode import WARNING
2526from attributecode import Error
2627from attributecode import gen
2728from unittest .case import skip
@@ -31,13 +32,15 @@ class GenTest(unittest.TestCase):
3132
3233 def test_check_duplicated_columns (self ):
3334 test_file = get_test_loc ('test_gen/dup_keys.csv' )
34- expected = [Error (ERROR , 'Duplicated column name(s): copyright with copyright\n Please correct the input and re-run.' )]
35+ expected = [Error (
36+ ERROR , 'Duplicated column name(s): copyright with copyright\n Please correct the input and re-run.' )]
3537 result = gen .check_duplicated_columns (test_file )
3638 assert expected == result
3739
3840 def test_check_duplicated_columns_handles_lower_upper_case (self ):
3941 test_file = get_test_loc ('test_gen/dup_keys_with_diff_case.csv' )
40- expected = [Error (ERROR , 'Duplicated column name(s): copyright with Copyright\n Please correct the input and re-run.' )]
42+ expected = [Error (
43+ ERROR , 'Duplicated column name(s): copyright with Copyright\n Please correct the input and re-run.' )]
4144 result = gen .check_duplicated_columns (test_file )
4245 assert expected == result
4346
@@ -46,15 +49,17 @@ def test_check_duplicated_about_resource(self):
4649 arp1 = '/test/test.c'
4750 arp2 = '/test/tmp/test.c'
4851 expected = Error (CRITICAL ,
49- "The input has duplicated values in 'about_resource' field: " + arp1 )
52+ "The input has duplicated values in 'about_resource' field: " + arp1 )
5053 result1 = gen .check_duplicated_about_resource (arp1 , arp_list )
5154 result2 = gen .check_duplicated_about_resource (arp2 , arp_list )
5255 assert result1 == expected
5356 assert result2 == ''
5457
5558 def test_check_newline_in_file_field (self ):
56- test_dict1 = {'about_resource' : '/test/test.c' , 'name' : 'test.c' , 'notice_file' : 'NOTICE\n NOTICE2' }
57- test_dict2 = {'about_resource' : '/test/test.c' , 'name' : 'test.c' , 'notice_file' : 'NOTICE, NOTICE2' }
59+ test_dict1 = {'about_resource' : '/test/test.c' ,
60+ 'name' : 'test.c' , 'notice_file' : 'NOTICE\n NOTICE2' }
61+ test_dict2 = {'about_resource' : '/test/test.c' ,
62+ 'name' : 'test.c' , 'notice_file' : 'NOTICE, NOTICE2' }
5863 expected = [
5964 Error (CRITICAL ,
6065 "New line character detected in 'notice_file' for '/test/test.c' which is not supported."
@@ -68,7 +73,7 @@ def test_check_about_resource_filename(self):
68736974 arp2 = '/test/t!est.c'
7075 msg = ("Invalid characters present in 'about_resource' "
71- "field: " + arp2 )
76+ "field: " + arp2 )
7277 expected2 = Error (ERROR , msg )
7378 result1 = gen .check_about_resource_filename (arp1 )
7479 result2 = gen .check_about_resource_filename (arp2 )
@@ -81,10 +86,10 @@ def test_load_inventory(self):
8186 errors , abouts = gen .load_inventory (location , base_dir = base_dir )
8287
8388 expected_num_errors = 29
84- assert len (errors ) == expected_num_errors
89+ assert len (errors ) == expected_num_errors
8590
8691 expected = (
87- '''about_resource: .
92+ '''about_resource: .
8893name: AboutCode
8994version: 0.11.0
9095description: |
@@ -102,23 +107,26 @@ def test_load_inventory_without_about_resource(self):
102107 location = get_test_loc ('test_gen/inv_no_about_resource.csv' )
103108 base_dir = get_temp_dir ()
104109 from_attrib = False
105- errors , abouts = gen .load_inventory (location , base_dir = base_dir , from_attrib = from_attrib )
106- expected_error = [Error (CRITICAL , "The essential field 'about_resource' is not found in the <input>" )]
110+ errors , abouts = gen .load_inventory (
111+ location , base_dir = base_dir , from_attrib = from_attrib )
112+ expected_error = [Error (
113+ CRITICAL , "The essential field 'about_resource' is not found in the <input>" )]
107114
108115 assert errors == expected_error
109- assert abouts == []
116+ assert abouts == []
110117
111118 def test_load_inventory_without_about_resource_from_attrib (self ):
112119 location = get_test_loc ('test_gen/inv_no_about_resource.csv' )
113120 base_dir = get_temp_dir ()
114121 from_attrib = True
115- errors , abouts = gen .load_inventory (location , base_dir = base_dir , from_attrib = from_attrib )
122+ errors , abouts = gen .load_inventory (
123+ location , base_dir = base_dir , from_attrib = from_attrib )
116124
117125 expected_num_errors = 0
118- assert len (errors ) == expected_num_errors
126+ assert len (errors ) == expected_num_errors
119127
120128 expected = (
121- '''about_resource: .
129+ '''about_resource: .
122130name: AboutCode
123131version: 0.11.0
124132license_expression: apache-2.0
@@ -132,7 +140,8 @@ def test_load_inventory_with_errors(self):
132140 base_dir = get_temp_dir ()
133141 errors , abouts = gen .load_inventory (location , base_dir = base_dir )
134142 expected_errors = [
135- Error (ERROR , "Field name: ['confirmed copyright'] contains illegal name characters (or empty spaces) and is ignored." ),
143+ Error (
144+ WARNING , "Field name: ['confirmed copyright'] contains illegal name characters (or empty spaces) and is ignored." ),
136145 Error (INFO , 'Field about_resource: Path' ),
137146 Error (INFO , "Field ['resource', 'test'] is a custom field." )
138147 ]
@@ -165,14 +174,13 @@ def test_load_inventory_simple_xlsx(self):
165174
166175 assert abouts [0 ].name .value == 'cryptohash-sha256'
167176 assert abouts [1 ].name .value == 'some_component'
168-
177+
169178 assert abouts [0 ].version .value == 'v 0.11.100.1'
170179 assert abouts [1 ].version .value == 'v 0.0.1'
171180
172181 assert abouts [0 ].license_expression .value == 'bsd-new and mit'
173182 assert abouts [1 ].license_expression .value == 'mit'
174183
175-
176184 def test_load_scancode_json (self ):
177185 location = get_test_loc ('test_gen/load/clean-text-0.3.0-lceupi.json' )
178186 inventory = gen .load_scancode_json (location )
@@ -188,12 +196,12 @@ def test_load_scancode_json(self):
188196 'authors' : [], 'packages' : [], 'emails' : [], 'urls' : [], 'files_count' : 9 ,
189197 'dirs_count' : 1 , 'size_count' : 32826 , 'scan_errors' : []}
190198
191- # We will only check the first element in the inventory list
199+ # We will only check the first element in the inventory list
192200 assert inventory [0 ] == expected
193201
194-
195202 def test_generation_dir_endswith_space (self ):
196- location = get_test_loc ('test_gen/inventory/complex/about_file_path_dir_endswith_space.csv' )
203+ location = get_test_loc (
204+ 'test_gen/inventory/complex/about_file_path_dir_endswith_space.csv' )
197205 base_dir = get_temp_dir ()
198206 errors , _abouts = gen .generate (location , base_dir )
199207 expected_errors_msg1 = 'contains directory name ends with spaces which is not allowed. Generation skipped.'
@@ -247,7 +255,7 @@ def test_generate(self):
247255
248256 result = [a .dumps () for a in abouts ][0 ]
249257 expected = (
250- '''about_resource: .
258+ '''about_resource: .
251259name: AboutCode
252260version: 0.11.0
253261description: |
@@ -268,7 +276,7 @@ def test_generate_multi_lic_issue_443(self):
268276
269277 result = [a .dumps () for a in abouts ][0 ]
270278 expected = (
271- '''about_resource: test
279+ '''about_resource: test
272280name: test
273281version: '1.5'
274282licenses:
@@ -293,7 +301,7 @@ def test_generate_multi_lic_issue_444(self):
293301
294302 result = [a .dumps () for a in abouts ][0 ]
295303 expected = (
296- '''about_resource: test.c
304+ '''about_resource: test.c
297305name: test.c
298306licenses:
299307 - key: License1
@@ -304,14 +312,15 @@ def test_generate_multi_lic_issue_444(self):
304312 assert expected == result
305313
306314 def test_generate_license_key_with_custom_file_450_no_fetch (self ):
307- location = get_test_loc ('test_gen/lic_issue_450/custom_and_valid_lic_key_with_file.csv' )
315+ location = get_test_loc (
316+ 'test_gen/lic_issue_450/custom_and_valid_lic_key_with_file.csv' )
308317 base_dir = get_temp_dir ()
309318
310319 errors , abouts = gen .generate (location , base_dir )
311320
312321 result = [a .dumps () for a in abouts ][0 ]
313322 expected = (
314- '''about_resource: test.c
323+ '''about_resource: test.c
315324name: test.c
316325license_expression: mit AND custom
317326licenses:
@@ -320,19 +329,19 @@ def test_generate_license_key_with_custom_file_450_no_fetch(self):
320329 )
321330 assert expected == result
322331
323-
324332 def test_generate_license_key_with_custom_file_450_with_fetch_with_order (self ):
325- location = get_test_loc ('test_gen/lic_issue_450/custom_and_valid_lic_key_with_file.csv' )
333+ location = get_test_loc (
334+ 'test_gen/lic_issue_450/custom_and_valid_lic_key_with_file.csv' )
326335 base_dir = get_temp_dir ()
327336
328337 errors , abouts = gen .generate (location , base_dir )
329338
330339 lic_dict = {u'mit' : [u'MIT License' ,
331- u'mit.LICENSE' ,
332- u'This component is released under MIT License.' ,
333- u'https://enterprise.dejacode.com/urn/?urn=urn:dje:license:mit' ,
334- u'mit'
335- ]}
340+ u'mit.LICENSE' ,
341+ u'This component is released under MIT License.' ,
342+ u'https://enterprise.dejacode.com/urn/?urn=urn:dje:license:mit' ,
343+ u'mit'
344+ ]}
336345 # The first row from the test file
337346 a = abouts [0 ]
338347 a .license_key .value .append ('mit' )
@@ -345,7 +354,7 @@ def test_generate_license_key_with_custom_file_450_with_fetch_with_order(self):
345354 result2 = b .dumps (lic_dict )
346355
347356 expected1 = (
348- '''about_resource: test.c
357+ '''about_resource: test.c
349358name: test.c
350359license_expression: mit AND custom
351360licenses:
@@ -361,7 +370,7 @@ def test_generate_license_key_with_custom_file_450_with_fetch_with_order(self):
361370 )
362371
363372 expected2 = (
364- '''about_resource: test.h
373+ '''about_resource: test.h
365374name: test.h
366375license_expression: custom AND mit
367376licenses:
0 commit comments