Skip to content

Commit 44a8b88

Browse files
committed
Fixed #276
We don't want to have the last segment of the `base_loc` to become the root of the returned path if both `base_loc` and `full_loc` are the same.
1 parent ee4eb95 commit 44a8b88

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/attributecode/util.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def get_about_locations(location):
160160
def get_relative_path(base_loc, full_loc):
161161
"""
162162
Return a posix path for a given full location relative to a base location.
163-
The last segment of the base_loc will become the first segment of the
164-
returned path.
163+
The first segment of the different between full_loc and base_loc will become
164+
the first segment of the returned path.
165165
"""
166166
def norm(p):
167167
if p.startswith(UNC_PREFIX) or p.startswith(to_posix(UNC_PREFIX)):
@@ -192,8 +192,9 @@ def norm(p):
192192
relative = posixpath.join(parent_dir, base_name)
193193
else:
194194
relative = path[len(base) + 1:]
195-
relative = posixpath.join(base_name, relative)
196-
195+
# We don't want to keep the first segment of the root of the returned path.
196+
# See https://github.com/nexB/attributecode/issues/276
197+
#relative = posixpath.join(base_name, relative)
197198
return relative
198199

199200

tests/test_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,8 @@ def test_collect_inventory_in_directory_with_correct_about_file_path(self):
10631063
_errors, abouts = model.collect_inventory(test_loc)
10641064
assert 2 == len(abouts)
10651065

1066-
expected = ['collect-inventory-errors/non-supported_date_format.ABOUT',
1067-
'collect-inventory-errors/supported_date_format.ABOUT']
1066+
expected = ['non-supported_date_format.ABOUT',
1067+
'supported_date_format.ABOUT']
10681068
result = [a.about_file_path for a in abouts]
10691069
assert sorted(expected) == sorted(result)
10701070

@@ -1125,7 +1125,7 @@ def test_collect_inventory_populate_about_file_path(self):
11251125
test_loc = get_test_loc('parse/complete')
11261126
errors, abouts = model.collect_inventory(test_loc)
11271127
assert [] == errors
1128-
expected = 'complete/about.ABOUT'
1128+
expected = 'about.ABOUT'
11291129
result = abouts[0].about_file_path
11301130
assert expected == result
11311131

@@ -1150,7 +1150,7 @@ def test_collect_inventory_works_with_relative_paths(self):
11501150
errors2, abouts2 = model.collect_inventory(test_loc2)
11511151
assert [] == errors1
11521152
assert [] == errors2
1153-
expected = 'complete/about.ABOUT'
1153+
expected = 'about.ABOUT'
11541154
result1 = abouts1[0].about_file_path
11551155
result2 = abouts2[0].about_file_path
11561156
assert expected == result1
@@ -1169,7 +1169,7 @@ def as_items(csvfile):
11691169
assert expected == result
11701170

11711171
def test_collect_inventory_basic_from_directory(self):
1172-
location = get_test_loc('inventory/basic/about')
1172+
location = get_test_loc('inventory/basic')
11731173
result = get_temp_file()
11741174
errors, abouts = model.collect_inventory(location)
11751175

@@ -1186,7 +1186,7 @@ def test_collect_inventory_basic_from_directory(self):
11861186
# and do the comparson, it may be best to apply the mapping to include theses keys
11871187
@expectedFailure
11881188
def test_collect_inventory_complex_from_directory(self):
1189-
location = get_test_loc('inventory/complex/about')
1189+
location = get_test_loc('inventory/complex')
11901190
result = get_temp_file()
11911191
errors, abouts = model.collect_inventory(location)
11921192

tests/test_util.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ def test_is_about_file(self):
232232
assert not util.is_about_file('no_about_ext.something')
233233

234234
def test_get_relative_path(self):
235-
test = [('/some/path', '/some/path/file', 'path/file'),
236-
('path', '/path/file', 'path/file'),
237-
('/path', '/path/file', 'path/file'),
238-
('/path/', '/path/file/', 'path/file'),
235+
test = [('/some/path', '/some/path/file', 'file'),
236+
('path', '/path/file', 'file'),
237+
('/path', '/path/file', 'file'),
238+
('/path/', '/path/file/', 'file'),
239239
('/path/', 'path/', 'path'),
240-
('/p1/p2/p3', '/p1/p2//p3/file', 'p3/file'),
241-
(r'c:\some/path', 'c:/some/path/file', 'path/file'),
242-
(r'c:\\some\\path\\', 'c:/some/path/file', 'path/file'),
240+
('/p1/p2/p3', '/p1/p2//p3/file', 'file'),
241+
(r'c:\some/path', 'c:/some/path/file', 'file'),
242+
(r'c:\\some\\path\\', 'c:/some/path/file', 'file'),
243243
]
244244
for base_loc, full_loc, expected in test:
245245
result = util.get_relative_path(base_loc, full_loc)

0 commit comments

Comments
 (0)