Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Do not copy whole directories for task tests (#2597)
Browse files Browse the repository at this point in the history
* Filter copied resources

* normpath(base_dir)

* Single file case

* Tweaks

* Create resource files in local computer test
  • Loading branch information
mfranciszkiewicz authored and badb committed Apr 8, 2018
1 parent 64df20c commit 5a47f77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
24 changes: 20 additions & 4 deletions golem/task/localcomputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,27 @@ def onerror(func, target_path, exc_info):
shutil.rmtree(self.test_task_res_path, onerror=onerror)

if resources:
if len(resources) == 1:
path = os.path.dirname(resources[0])
if len(resources) == 1 and os.path.isdir(resources[0]):
shutil.copytree(resources[0], self.test_task_res_path)
else:
path = common_dir(resources)
shutil.copytree(path, self.test_task_res_path)
# no trailing separator
if len(resources) == 1:
base_dir = os.path.dirname(resources[0])
else:
base_dir = common_dir(resources)

base_dir = os.path.normpath(base_dir)

for resource in filter(None, resources):
norm_path = os.path.normpath(resource)

sub_path = norm_path.replace(base_dir + os.path.sep, '', 1)
sub_dir = os.path.dirname(sub_path)
dst_dir = os.path.join(self.test_task_res_path, sub_dir)
os.makedirs(dst_dir, exist_ok=True)

name = os.path.basename(resource)
shutil.copy2(resource, os.path.join(dst_dir, name))

for res in self.additional_resources:
if not os.path.exists(self.test_task_res_path):
Expand Down
3 changes: 3 additions & 0 deletions tests/golem/task/test_localcomputer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def reset_permissions(_path):
resources = [os.path.join(resource_dir, 'file')]

Path(existing_file).touch()
for resource in resources:
Path(resource).touch()

remove_permissions(existing_file)

lc._prepare_resources(resources)
Expand Down

0 comments on commit 5a47f77

Please sign in to comment.