Skip to content

Commit

Permalink
fix: Merge pull request #312 from CoshUS/fix/dependency-create-directory
Browse files Browse the repository at this point in the history
fix: Added Create Directory before Copy
  • Loading branch information
CoshUS authored Dec 3, 2021
2 parents 71e507f + 7f151fa commit c03a233
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions aws_lambda_builders/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def execute(self):
if os.path.isdir(dependencies_source):
copytree(dependencies_source, new_destination)
else:
os.makedirs(os.path.dirname(dependencies_source), exist_ok=True)
shutil.copy2(dependencies_source, new_destination)


Expand Down
8 changes: 7 additions & 1 deletion tests/unit/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,32 @@ def test_must_copy(self, copytree_mock):


class TestCopyDependenciesAction_execute(TestCase):
@patch("aws_lambda_builders.actions.os.makedirs")
@patch("aws_lambda_builders.actions.os.path.dirname")
@patch("aws_lambda_builders.actions.shutil.copy2")
@patch("aws_lambda_builders.actions.copytree")
@patch("aws_lambda_builders.actions.os.path.isdir")
@patch("aws_lambda_builders.actions.os.listdir")
@patch("aws_lambda_builders.actions.os.path.join")
def test_must_copy(self, path_mock, listdir_mock, isdir_mock, copytree_mock, copy2_mock):
def test_must_copy(
self, path_mock, listdir_mock, isdir_mock, copytree_mock, copy2_mock, dirname_mock, makedirs_mock
):
source_dir = "source"
artifact_dir = "artifact"
dest_dir = "dest"

listdir_mock.side_effect = [[1], [1, 2, 3]]
path_mock.side_effect = ["dir1", "dir2", "file1", "file2"]
isdir_mock.side_effect = [True, False]
dirname_mock.side_effect = ["parent_dir_1"]
action = CopyDependenciesAction(source_dir, artifact_dir, dest_dir)
action.execute()

listdir_mock.assert_any_call(source_dir)
listdir_mock.assert_any_call(artifact_dir)
copytree_mock.assert_called_once_with("dir1", "dir2")
copy2_mock.assert_called_once_with("file1", "file2")
makedirs_mock.assert_called_once_with("parent_dir_1", exist_ok=True)


class TestMoveDependenciesAction_execute(TestCase):
Expand Down

0 comments on commit c03a233

Please sign in to comment.