Skip to content

Commit e204d7e

Browse files
committed
Lower the severity level of illegal field name from ERROR to WARNING
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 0e904c0 commit e204d7e

File tree

4 files changed

+46
-38
lines changed

4 files changed

+46
-38
lines changed

src/attributecode/gen.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
185185
if errors:
186186
return errors, abouts
187187
except Exception as e:
188-
print("!!!!!!!!!!!!!!!!")
189-
print(str(e))
190188
# TODO: why catch ALL Exception
191189
msg = "The essential field 'about_resource' is not found in the <input>"
192190
errors.append(Error(CRITICAL, msg))
@@ -253,6 +251,7 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
253251
running_inventory=False,
254252
reference_dir=reference_dir,
255253
)
254+
256255
for severity, message in ld_errors:
257256
if 'Custom Field' in message:
258257
field_name = message.replace('Custom Field: ', '').strip()

src/attributecode/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ def hydrate(self, fields):
957957
if illegal_name_list:
958958
msg = ('Field name: %(illegal_name_list)r contains illegal name characters '
959959
'(or empty spaces) and is ignored.')
960-
errors.append(Error(ERROR, msg % locals()))
960+
errors.append(Error(WARNING, msg % locals()))
961961
return errors
962962

963963
def process(self, fields, about_file_path, running_inventory=False,

tests/test_gen.py

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from attributecode import ERROR
2323
from attributecode import INFO
2424
from attributecode import CRITICAL
25+
from attributecode import WARNING
2526
from attributecode import Error
2627
from attributecode import gen
2728
from 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\nPlease correct the input and re-run.')]
35+
expected = [Error(
36+
ERROR, 'Duplicated column name(s): copyright with copyright\nPlease 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\nPlease correct the input and re-run.')]
42+
expected = [Error(
43+
ERROR, 'Duplicated column name(s): copyright with Copyright\nPlease 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\nNOTICE2'}
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\nNOTICE2'}
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):
6873
arp1 = '/test/[email protected]'
6974
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: .
8893
name: AboutCode
8994
version: 0.11.0
9095
description: |
@@ -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: .
122130
name: AboutCode
123131
version: 0.11.0
124132
license_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: .
251259
name: AboutCode
252260
version: 0.11.0
253261
description: |
@@ -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
272280
name: test
273281
version: '1.5'
274282
licenses:
@@ -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
297305
name: test.c
298306
licenses:
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
315324
name: test.c
316325
license_expression: mit AND custom
317326
licenses:
@@ -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
349358
name: test.c
350359
license_expression: mit AND custom
351360
licenses:
@@ -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
365374
name: test.h
366375
license_expression: custom AND mit
367376
licenses:

tests/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def test_About_rejects_non_ascii_names_and_accepts_unicode_values(self):
582582
test_file = get_test_loc('test_model/parse/non_ascii_field_name_value.about')
583583
a = model.About(test_file)
584584
expected = [
585-
Error(ERROR, "Field name: ['mat\xedas'] contains illegal name characters (or empty spaces) and is ignored.")
585+
Error(WARNING, "Field name: ['mat\xedas'] contains illegal name characters (or empty spaces) and is ignored.")
586586
]
587587
assert expected == a.errors
588588

0 commit comments

Comments
 (0)