Skip to content

Commit eb40e78

Browse files
authored
fix: Create scratch_dir in builder.py and bump version to 0.0.4.dev1 (#50)
1 parent 84980da commit eb40e78

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

aws_lambda_builders/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
22
AWS Lambda Builder Library
33
"""
4-
__version__ = '0.0.3'
4+
__version__ = '0.0.4.dev1'
55
RPC_PROTOCOL_VERSION = "0.1"

aws_lambda_builders/builder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import importlib
6+
import os
67
import logging
78

89
from aws_lambda_builders.registry import get_workflow, DEFAULT_REGISTRY
@@ -93,6 +94,8 @@ def build(self, source_dir, artifacts_dir, scratch_dir, manifest_path,
9394
if runtime:
9495
self._validate_runtime(runtime)
9596

97+
if not os.path.exists(scratch_dir):
98+
os.makedirs(scratch_dir)
9699

97100
workflow = self.selected_workflow_cls(source_dir,
98101
artifacts_dir,

requirements/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
six~=1.11.0
1+
six~=1.11

tests/functional/test_builder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def setUp(self):
1919

2020
self.source_dir = tempfile.mkdtemp()
2121
self.artifacts_dir = tempfile.mkdtemp()
22+
self.scratch_dir = os.path.join(tempfile.mkdtemp(), "scratch")
2223
self.hello_builder = LambdaBuilder(language="test",
2324
dependency_manager="test",
2425
application_framework="test",
@@ -34,6 +35,7 @@ def tearDown(self):
3435
self.hello_builder._clear_workflows()
3536
shutil.rmtree(self.source_dir)
3637
shutil.rmtree(self.artifacts_dir)
38+
shutil.rmtree(self.scratch_dir)
3739

3840
# Remove the workflows folder from PYTHONPATH
3941
sys.path.remove(self.TEST_WORKFLOWS_FOLDER)
@@ -42,7 +44,7 @@ def test_run_hello_workflow(self):
4244

4345
self.hello_builder.build(self.source_dir,
4446
self.artifacts_dir,
45-
"/ignored",
47+
self.scratch_dir,
4648
"/ignored")
4749

4850
self.assertTrue(os.path.exists(self.expected_filename))

tests/functional/test_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def setUp(self):
1919

2020
self.source_dir = tempfile.mkdtemp()
2121
self.artifacts_dir = tempfile.mkdtemp()
22+
self.scratch_dir = os.path.join(tempfile.mkdtemp(), "scratch")
2223

2324
# Capabilities supported by the Hello workflow
2425
self.language = "test"
@@ -38,6 +39,7 @@ def setUp(self):
3839
def tearDown(self):
3940
shutil.rmtree(self.source_dir)
4041
shutil.rmtree(self.artifacts_dir)
42+
shutil.rmtree(self.scratch_dir)
4143

4244
@parameterized.expand([
4345
("request_through_stdin"),
@@ -58,7 +60,7 @@ def test_run_hello_workflow(self, flavor):
5860
"supported_workflows": [self.HELLO_WORKFLOW_MODULE],
5961
"source_dir": self.source_dir,
6062
"artifacts_dir": self.artifacts_dir,
61-
"scratch_dir": "/ignored",
63+
"scratch_dir": self.scratch_dir,
6264
"manifest_path": "/ignored",
6365
"runtime": "ignored",
6466
"optimizations": {},

tests/unit/test_builder.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
from unittest import TestCase
33
from mock import patch, call, Mock
4+
from parameterized import parameterized, param
45

56
from aws_lambda_builders.builder import LambdaBuilder
67
from aws_lambda_builders.workflow import Capability, BaseWorkflow
@@ -99,12 +100,19 @@ def setUp(self):
99100
self.lang_framework = "pip"
100101
self.app_framework = "chalice"
101102

103+
@parameterized.expand([
104+
param(True),
105+
param(False)
106+
])
107+
@patch('aws_lambda_builders.builder.os')
102108
@patch('aws_lambda_builders.builder.importlib')
103109
@patch('aws_lambda_builders.builder.get_workflow')
104-
def test_with_mocks(self, get_workflow_mock, importlib_mock):
110+
def test_with_mocks(self, scratch_dir_exists, get_workflow_mock, importlib_mock, os_mock):
105111
workflow_cls = Mock()
106112
workflow_instance = workflow_cls.return_value = Mock()
107113

114+
os_mock.path.exists.return_value = scratch_dir_exists
115+
108116
get_workflow_mock.return_value = workflow_cls
109117

110118
with patch.object(LambdaBuilder, "_validate_runtime"):
@@ -116,3 +124,8 @@ def test_with_mocks(self, get_workflow_mock, importlib_mock):
116124
workflow_cls.assert_called_with("source_dir", "artifacts_dir", "scratch_dir", "manifest_path",
117125
runtime="runtime", optimizations="optimizations", options="options")
118126
workflow_instance.run.assert_called_once()
127+
os_mock.path.exists.assert_called_once_with("scratch_dir")
128+
if scratch_dir_exists:
129+
os_mock.makedirs.not_called()
130+
else:
131+
os_mock.makedirs.assert_called_once_with("scratch_dir")

0 commit comments

Comments
 (0)