diff --git a/Makefile b/Makefile index d43feb880..0d99cca91 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/aws_lambda_builders/workflows/python_pip/workflow.py b/aws_lambda_builders/workflows/python_pip/workflow.py index f5af20ce9..fb2582b0d 100644 --- a/aws_lambda_builders/workflows/python_pip/workflow.py +++ b/aws_lambda_builders/workflows/python_pip/workflow.py @@ -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", diff --git a/tests/functional/test_utils.py b/tests/functional/test_utils.py new file mode 100644 index 000000000..69dcd3390 --- /dev/null +++ b/tests/functional/test_utils.py @@ -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()