Skip to content

Commit 195d5a2

Browse files
committed
Merge branch '299-custom-key-problem-in-mapping' into develop
2 parents 9fd9a9c + 3bfa045 commit 195d5a2

File tree

6 files changed

+49
-4
lines changed

6 files changed

+49
-4
lines changed

src/attributecode/gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def load_inventory(location, base_dir, license_notice_text_location=None,
164164
about = model.About(about_file_path=afp)
165165
about.location = loc
166166
running_inventory = False
167-
ld_errors = about.load_dict(fields, base_dir, running_inventory, license_notice_text_location, with_empty=False)
167+
ld_errors = about.load_dict(fields, base_dir, running_inventory, use_mapping, license_notice_text_location, with_empty=False)
168168
# 'about_resource' field will be generated during the process.
169169
# No error need to be raise for the missing 'about_resource'.
170170
for e in ld_errors:

src/attributecode/mapping.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ version: Confirmed Version
3939
copyright: Confirmed Copyright
4040

4141
# Custom Fields
42-
license_expression: dje_license_key
42+
license_expression: dje_license_key
43+
resource: Resource

src/attributecode/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ def load_lines(self, lines, base_dir):
10181018
self.errors = errors
10191019
return errors
10201020

1021-
def load_dict(self, fields_dict, base_dir, running_inventory=False,
1021+
def load_dict(self, fields_dict, base_dir, running_inventory=False, use_mapping=False,
10221022
license_notice_text_location=None, with_empty=True):
10231023
"""
10241024
Load the ABOUT file from a fields name/value mapping.
@@ -1032,7 +1032,7 @@ def load_dict(self, fields_dict, base_dir, running_inventory=False,
10321032
fields = [(n, v) for n, v in fields_dict.items() if v]
10331033
errors = self.process(
10341034
fields, about_file_path, running_inventory, base_dir,
1035-
license_notice_text_location)
1035+
license_notice_text_location, use_mapping)
10361036
self.errors = errors
10371037
return errors
10381038

tests/test_gen.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,33 @@ def test_load_inventory(self):
7171
for a in abouts]
7272
assert expected == result
7373

74+
def test_load_inventory_with_mapping(self):
75+
location = get_test_loc('gen/inv4.csv')
76+
base_dir = get_test_loc('inv')
77+
license_notice_text_location = None
78+
use_mapping = True
79+
errors, abouts = gen.load_inventory(location,
80+
base_dir,
81+
license_notice_text_location,
82+
use_mapping)
83+
expected_errors = [
84+
Error(INFO, 'Field test is not a supported field and is not defined in the mapping file. This field is ignored.'),
85+
Error(INFO, 'Field resource is a custom field')]
86+
assert sorted(expected_errors) == sorted(errors)
87+
88+
expected = [u'about_resource: .\n'
89+
u'name: AboutCode\n'
90+
u'version: 0.11.0\n'
91+
u'description: |\n'
92+
u' multi\n'
93+
u' line\n'
94+
u'copyright: Copyright (c) nexB, Inc.\n'
95+
u'resource: this.ABOUT\n'
96+
]
97+
result = [a.dumps(with_absent=False, with_empty=False)
98+
for a in abouts]
99+
assert expected == result
100+
74101
def test_generation_dir_endswith_space(self):
75102
location = get_test_loc('inventory/complex/about_file_path_dir_endswith_space.csv')
76103
base_dir = get_temp_dir()

tests/test_util.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,17 @@ def test_get_locations_with_very_long_path(self):
324324
test_loc = extract_test_loc('longpath.zip')
325325
result = list(util.get_locations(test_loc))
326326
assert any(longpath in r for r in result)
327+
328+
def test_apply_mapping(self):
329+
input = [OrderedDict([('about_resource', '.'),
330+
('name', 'test'),
331+
('confirmed version', '1'),
332+
('confirmed copyright', 'Copyright (c) 2013-2017 nexB Inc.')
333+
])]
334+
expected = [OrderedDict([('about_resource', '.'),
335+
('name', 'test'),
336+
('version', '1'),
337+
('copyright', 'Copyright (c) 2013-2017 nexB Inc.')
338+
])]
339+
assert util.apply_mapping(input) == expected
340+

tests/testdata/gen/inv4.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
about_file_path,about_resource,name,version,description,Confirmed Copyright,Resource,test
2+
inv/this.ABOUT,.,AboutCode,0.11.0,"multi
3+
line","Copyright (c) nexB, Inc.",this.ABOUT,This is a test

0 commit comments

Comments
 (0)