Skip to content

Commit

Permalink
fix: Create scratch_dir in builder.py and bump version to 0.0.4.dev1 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jfuss authored Dec 10, 2018
1 parent 84980da commit eb40e78
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion aws_lambda_builders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
AWS Lambda Builder Library
"""
__version__ = '0.0.3'
__version__ = '0.0.4.dev1'
RPC_PROTOCOL_VERSION = "0.1"
3 changes: 3 additions & 0 deletions aws_lambda_builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import importlib
import os
import logging

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

if not os.path.exists(scratch_dir):
os.makedirs(scratch_dir)

workflow = self.selected_workflow_cls(source_dir,
artifacts_dir,
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
six~=1.11.0
six~=1.11
4 changes: 3 additions & 1 deletion tests/functional/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def setUp(self):

self.source_dir = tempfile.mkdtemp()
self.artifacts_dir = tempfile.mkdtemp()
self.scratch_dir = os.path.join(tempfile.mkdtemp(), "scratch")
self.hello_builder = LambdaBuilder(language="test",
dependency_manager="test",
application_framework="test",
Expand All @@ -34,6 +35,7 @@ def tearDown(self):
self.hello_builder._clear_workflows()
shutil.rmtree(self.source_dir)
shutil.rmtree(self.artifacts_dir)
shutil.rmtree(self.scratch_dir)

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

self.hello_builder.build(self.source_dir,
self.artifacts_dir,
"/ignored",
self.scratch_dir,
"/ignored")

self.assertTrue(os.path.exists(self.expected_filename))
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def setUp(self):

self.source_dir = tempfile.mkdtemp()
self.artifacts_dir = tempfile.mkdtemp()
self.scratch_dir = os.path.join(tempfile.mkdtemp(), "scratch")

# Capabilities supported by the Hello workflow
self.language = "test"
Expand All @@ -38,6 +39,7 @@ def setUp(self):
def tearDown(self):
shutil.rmtree(self.source_dir)
shutil.rmtree(self.artifacts_dir)
shutil.rmtree(self.scratch_dir)

@parameterized.expand([
("request_through_stdin"),
Expand All @@ -58,7 +60,7 @@ def test_run_hello_workflow(self, flavor):
"supported_workflows": [self.HELLO_WORKFLOW_MODULE],
"source_dir": self.source_dir,
"artifacts_dir": self.artifacts_dir,
"scratch_dir": "/ignored",
"scratch_dir": self.scratch_dir,
"manifest_path": "/ignored",
"runtime": "ignored",
"optimizations": {},
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/test_builder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

from unittest import TestCase
from mock import patch, call, Mock
from parameterized import parameterized, param

from aws_lambda_builders.builder import LambdaBuilder
from aws_lambda_builders.workflow import Capability, BaseWorkflow
Expand Down Expand Up @@ -99,12 +100,19 @@ def setUp(self):
self.lang_framework = "pip"
self.app_framework = "chalice"

@parameterized.expand([
param(True),
param(False)
])
@patch('aws_lambda_builders.builder.os')
@patch('aws_lambda_builders.builder.importlib')
@patch('aws_lambda_builders.builder.get_workflow')
def test_with_mocks(self, get_workflow_mock, importlib_mock):
def test_with_mocks(self, scratch_dir_exists, get_workflow_mock, importlib_mock, os_mock):
workflow_cls = Mock()
workflow_instance = workflow_cls.return_value = Mock()

os_mock.path.exists.return_value = scratch_dir_exists

get_workflow_mock.return_value = workflow_cls

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

0 comments on commit eb40e78

Please sign in to comment.