Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ init:

test:
# Run unit tests
# Fail if coverage falls below 90%
LAMBDA_BUILDERS_DEV=1 pytest --cov aws_lambda_builders --cov-report term-missing --cov-fail-under 90 tests/unit tests/functional
# Fail if coverage falls below 94%
LAMBDA_BUILDERS_DEV=1 pytest --cov aws_lambda_builders --cov-report term-missing --cov-fail-under 94 tests/unit tests/functional

func-test:
LAMBDA_BUILDERS_DEV=1 pytest tests/functional
Expand Down
5 changes: 4 additions & 1 deletion aws_lambda_builders/workflows/python_pip/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class PythonPipWorkflow(BaseWorkflow):

# Common source files to exclude from build artifacts output
# Trimmed version of https://github.com/github/gitignore/blob/master/Python.gitignore
EXCLUDED_FILES = (".git",
EXCLUDED_FILES = (
".aws-sam", ".chalice",

".git",

# Compiled files
"*.pyc", "__pycache__", "*.so",
Expand Down
50 changes: 50 additions & 0 deletions tests/functional/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
import tempfile
import shutil

from unittest import TestCase

from aws_lambda_builders.utils import copytree

class TestCopyTree(TestCase):

def setUp(self):
self.source = tempfile.mkdtemp()
self.dest = tempfile.mkdtemp()

def tearDown(self):
shutil.rmtree(self.source)
shutil.rmtree(self.dest)

def test_must_copy_files_recursively(self):
file(self.source, "a", "file.txt")
file(self.source, "a", "b", "file.txt")
file(self.source, "a", "c", "file.txt")

copytree(self.source, self.dest)
self.assertTrue(os.path.exists(os.path.join(self.dest, "a", "file.txt")))
self.assertTrue(os.path.exists(os.path.join(self.dest, "a", "b", "file.txt")))
self.assertTrue(os.path.exists(os.path.join(self.dest, "a", "c", "file.txt")))

def test_must_respect_excludes_list(self):
file(self.source, ".git", "file.txt")
file(self.source, "nested", ".aws-sam", "file.txt")
file(self.source, "main.pyc")
file(self.source, "a", "c", "file.txt")

excludes = [".git", ".aws-sam", "*.pyc"]

copytree(self.source, self.dest, ignore=shutil.ignore_patterns(*excludes))
self.assertEquals(set(os.listdir(self.dest)), {"nested", "a"})
self.assertEquals(set(os.listdir(os.path.join(self.dest, "nested"))), set())
self.assertEquals(set(os.listdir(os.path.join(self.dest, "a"))), {"c"})
self.assertEquals(set(os.listdir(os.path.join(self.dest, "a"))), {"c"})

def file(*args):
path = os.path.join(*args)
basedir = os.path.dirname(path)
if not os.path.exists(basedir):
os.makedirs(basedir)

# empty file
open(path, 'a').close()