Skip to content

Commit 14819d5

Browse files
committed
#22 - Fixed tests
1 parent d87bfb5 commit 14819d5

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/attributecode/model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,10 @@ def get_copy_list(abouts, location):
13221322
if file_exist:
13231323
for k in about.about_resource.value:
13241324
from_path = about.about_resource.value.get(k)
1325-
norm_from_path = norm(from_path)
1325+
if on_windows:
1326+
norm_from_path = norm(from_path)
1327+
else:
1328+
norm_from_path = os.path.normpath(from_path)
13261329
# Get the relative path
13271330
relative_from_path = norm_from_path.partition(util.norm(location))[2]
13281331
if os.path.isdir(from_path):

src/attributecode/util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def copy_file(from_path, to_path):
492492
to_path = add_unc(to_path)
493493

494494
# Strip the white spaces
495-
from_path = norm(from_path.strip())
495+
from_path = from_path.strip()
496496
to_path = to_path.strip()
497497
# Errors will be captured when doing the validation
498498
if not os.path.exists(from_path):
@@ -503,17 +503,19 @@ def copy_file(from_path, to_path):
503503
try:
504504
if os.path.isdir(from_path):
505505
# Copy the whole directory structure
506+
if from_path.endswith('/'):
507+
from_path = from_path.rpartition('/')[0]
506508
folder_name = os.path.basename(from_path)
507509
to_path = os.path.join(to_path, folder_name)
508510
if os.path.exists(to_path):
509-
msg = norm(to_path)+ ' is already existed and is replaced by ' + norm(from_path)
511+
msg = to_path + ' is already existed and is replaced by ' + from_path
510512
error.append(Error(WARNING, msg))
511513
copy_tree(from_path, to_path)
512514
else:
513515
file_name = os.path.basename(from_path)
514516
to_file_path = os.path.join(to_path, file_name)
515517
if os.path.exists(to_file_path):
516-
msg = norm(to_file_path)+ ' is already existed and is replaced by ' + norm(from_path)
518+
msg = to_file_path + ' is already existed and is replaced by ' + from_path
517519
error.append(Error(WARNING, msg))
518520
shutil.copy2(from_path, to_path)
519521
return error

tests/test_model.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,11 +1254,14 @@ def test_get_copy_list(self):
12541254
errors, abouts = model.collect_inventory(location)
12551255
copy_list, err = model.get_copy_list(abouts, location)
12561256
assert err == []
1257-
norm_list = []
1258-
for c in copy_list:
1259-
norm_list.append(norm(c))
12601257
expected = [os.path.join(location, 'this.c'), os.path.join(location, 'test/subdir')]
1261-
assert norm_list == expected
1258+
if on_windows:
1259+
norm_list = []
1260+
for c in copy_list:
1261+
norm_list.append(norm(c))
1262+
assert norm_list == expected
1263+
else:
1264+
assert copy_list == expected
12621265

12631266
class FetchLicenseTest(unittest.TestCase):
12641267

0 commit comments

Comments
 (0)