Skip to content

Commit 76aa751

Browse files
committed
#492 - Update test and code enhancement
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 6e5a1a9 commit 76aa751

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/attributecode/cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,9 @@ def get_error_messages(errors, quiet=False, verbose=False):
842842
msg = '{sevcode}: {message}'.format(**locals())
843843
if not quiet:
844844
if verbose:
845-
messages .append(msg)
845+
messages.append(msg)
846846
elif severity >= WARNING:
847-
messages .append(msg)
847+
messages.append(msg)
848848
return messages, severe_errors_count
849849

850850
######################################################################

src/attributecode/gen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,5 +391,4 @@ def generate(location, base_dir, android=None, reference_dir=None, fetch_license
391391
errors.append(Error(ERROR, msg))
392392
else:
393393
about.dump_android_notice(path, notice_dict[path])
394-
395394
return errors, abouts

src/attributecode/model.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,14 +1337,23 @@ def collect_inventory(location):
13371337
name_errors = util.check_file_names(about_locations)
13381338
errors.extend(name_errors)
13391339
abouts = []
1340+
custom_fields_list = []
13401341
for about_loc in about_locations:
13411342
about_file_path = util.get_relative_path(input_location, about_loc)
13421343
about = About(about_loc, about_file_path)
13431344
# Insert about_file_path reference to the error
13441345
for severity, message in about.errors:
1345-
msg = (about_file_path + ": " + message)
1346-
errors.append(Error(severity, msg))
1346+
if 'is a custom field' in message:
1347+
field_name = message.replace('Field', '').replace('is a custom field.', '').strip()
1348+
if not field_name in custom_fields_list:
1349+
custom_fields_list.append(field_name)
1350+
else:
1351+
msg = (about_file_path + ": " + message)
1352+
errors.append(Error(severity, msg))
13471353
abouts.append(about)
1354+
if custom_fields_list:
1355+
custom_fields_err_msg = 'Field ' + str(custom_fields_list) + ' is a custom field.'
1356+
errors.append(Error(INFO, custom_fields_err_msg))
13481357
return errors, abouts
13491358

13501359

tests/test_model.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,7 @@ def test_collect_inventory_return_errors(self):
10311031
err_msg1 = 'non-supported_date_format.ABOUT: Field about_resource: Path %s not found' % file_path1
10321032
err_msg2 = 'supported_date_format.ABOUT: Field about_resource: Path %s not found' % file_path2
10331033
expected_errors = [
1034-
Error(INFO, 'non-supported_date_format.ABOUT: Field date is a custom field.'),
1035-
Error(INFO, 'supported_date_format.ABOUT: Field date is a custom field.'),
1034+
Error(INFO, "Field ['date'] is a custom field."),
10361035
Error(INFO, err_msg1),
10371036
Error(INFO, err_msg2)]
10381037
assert sorted(expected_errors) == sorted(errors)
@@ -1105,18 +1104,17 @@ def test_collect_inventory_with_license_expression(self):
11051104
def test_collect_inventory_always_collects_custom_fieldsg(self):
11061105
test_loc = get_test_loc('test_model/inventory/custom_fields.ABOUT')
11071106
errors, abouts = model.collect_inventory(test_loc)
1108-
expected_msg1 = 'Field resource is a custom field'
1109-
assert len(errors) == 2
1110-
assert expected_msg1 in errors[0].message
1111-
# The not supported 'resource' value is collected
1107+
expected_msg = "Field ['resource', 'custom_mapping'] is a custom field."
1108+
assert len(errors) == 1
1109+
assert expected_msg in errors[0].message
1110+
# The value of the custom field: 'resource' is collected
11121111
assert abouts[0].resource.value
11131112

11141113
def test_collect_inventory_does_not_raise_error_and_maintains_order_on_custom_fields(self):
11151114
test_loc = get_test_loc('test_model/inventory/custom_fields2.ABOUT')
11161115
errors, abouts = model.collect_inventory(test_loc)
11171116
expected_errors = [
1118-
Error(INFO, 'inventory/custom_fields2.ABOUT: Field resource is a custom field.'),
1119-
Error(INFO, 'inventory/custom_fields2.ABOUT: Field custom_mapping is a custom field.')
1117+
Error(INFO, "Field ['resource', 'custom_mapping'] is a custom field.")
11201118
]
11211119
assert expected_errors == errors
11221120
expected = [u'about_resource: .\nname: test\nresource: .\ncustom_mapping: test\n']

0 commit comments

Comments
 (0)