Skip to content

Commit 3614f97

Browse files
committed
The error from copy_file shouldn't be a list.
1 parent e4bc9a7 commit 3614f97

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/attributecode/util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,10 @@ def copy_license_notice_files(fields, base_dir, reference_dir, afp):
480480

481481

482482
def copy_file(from_path, to_path):
483-
error = []
483+
error = ''
484484
# Return if the from_path is empty or None.
485485
if not from_path:
486-
return []
486+
return
487487

488488
if on_windows:
489489
if not from_path.startswith(UNC_PREFIXES):
@@ -496,7 +496,7 @@ def copy_file(from_path, to_path):
496496
to_path = to_path.strip()
497497
# Errors will be captured when doing the validation
498498
if not os.path.exists(from_path):
499-
return []
499+
return ''
500500

501501
if not posixpath.exists(to_path):
502502
os.makedirs(to_path)
@@ -509,19 +509,19 @@ def copy_file(from_path, to_path):
509509
to_path = os.path.join(to_path, folder_name)
510510
if os.path.exists(to_path):
511511
msg = to_path + ' is already existed and is replaced by ' + from_path
512-
error.append(Error(WARNING, msg))
512+
error = Error(WARNING, msg)
513513
copy_tree(from_path, to_path)
514514
else:
515515
file_name = os.path.basename(from_path)
516516
to_file_path = os.path.join(to_path, file_name)
517517
if os.path.exists(to_file_path):
518518
msg = to_file_path + ' is already existed and is replaced by ' + from_path
519-
error.append(Error(WARNING, msg))
519+
error = Error(WARNING, msg)
520520
shutil.copy2(from_path, to_path)
521521
return error
522522
except Exception as e:
523523
msg = 'Cannot copy file at %(from_path)r.' % locals()
524-
error.append(Error(CRITICAL, msg))
524+
error = Error(CRITICAL, msg)
525525
return error
526526

527527

tests/test_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def test_copy_file(self):
637637
from os import listdir
638638
copied_files = listdir(des)
639639
assert len(licenses) == len(copied_files)
640-
assert err == []
640+
assert err == ''
641641
for license in licenses:
642642
assert license in copied_files
643643

@@ -646,7 +646,7 @@ def test_copy_file_with_dir(self):
646646
test_dir = get_test_loc('test_util/licenses/')
647647
licenses = ['mit.LICENSE', 'mit2.LICENSE', 'public-domain.LICENSE']
648648
err = util.copy_file(test_dir, des)
649-
assert err == []
649+
assert err == ''
650650

651651
import os
652652
files_list = []

0 commit comments

Comments
 (0)