From 5287b001c690005495860fc09b08cf524eed5a8a Mon Sep 17 00:00:00 2001 From: Kevin Ndung'u Date: Fri, 27 Mar 2015 16:56:55 +0300 Subject: [PATCH 1/4] Add test for cookiecutter substitution --- tests/__init__.py | 0 tests/test_cookiecutter_substitution.py | 41 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_cookiecutter_substitution.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_cookiecutter_substitution.py b/tests/test_cookiecutter_substitution.py new file mode 100644 index 00000000..4cef245c --- /dev/null +++ b/tests/test_cookiecutter_substitution.py @@ -0,0 +1,41 @@ +import os +import re +import shutil +import unittest +from os.path import dirname, exists, join + +from cookiecutter.main import cookiecutter + + +class TestCookiecutterSubstitution(unittest.TestCase): + """Test that all cookiecutter instances are substituted""" + + cookiecutter(dirname(dirname(__file__)), no_input=True) + + destpath = join(dirname(dirname(__file__)), 'project_name') + + def tearDown(self): + if exists(self.destpath): + shutil.rmtree(self.destpath) + + def test_all_cookiecutter_instances_are_substituted(self): + # Build a list containing absolute paths to the generated files + paths = [os.path.join(dirpath, file_path) + for dirpath, subdirs, files in os.walk(self.destpath) + for file_path in files] + + # Construct the cookiecutter search pattern + pattern = "{{(\s?cookiecutter)[.](.*?)}}" + re_obj = re.compile(pattern) + + # Assert that no match is found in any of the files + for path in paths: + for line in open(path, 'r'): + match = re_obj.search(line) + self.assertIsNone( + match, + "cookiecutter variable not replaced in {}".format(path)) + + +if __name__ == '__main__': + unittest.main() From b71b9b9da2e9cb433ebd901e455a3da7a91983ce Mon Sep 17 00:00:00 2001 From: Kevin Ndung'u Date: Fri, 27 Mar 2015 16:58:09 +0300 Subject: [PATCH 2/4] Add Makefile to ease testing add 'test' directive to Makefile to run tests --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..ddb3a803 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +.PHONY: test + +test: + py.test -q tests/*.py From c75a455babeb2aa97240f201a4b1f26c72340488 Mon Sep 17 00:00:00 2001 From: Kevin Ndung'u Date: Fri, 27 Mar 2015 17:00:29 +0300 Subject: [PATCH 3/4] Add dev requirements file --- dev-requirements.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 dev-requirements.txt diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 00000000..fbcc80e1 --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1,3 @@ +cookiecutter +pep8 +pytest From 93c330f063a8c77dcc514f750cecbf15fb831f71 Mon Sep 17 00:00:00 2001 From: Kevin Ndung'u Date: Fri, 27 Mar 2015 17:04:11 +0300 Subject: [PATCH 4/4] Add new configs to .travis.yml - Add directive to install requirements - Add 'make test' to list of test commands --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index dd79a56b..a0dc7921 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,12 @@ language: python before_install: - time pip install pep8 +install: +- pip install -r dev-requirements.txt + script: - pep8 --ignore E201,E202 --max-line-length=120 --exclude='migrations' . + - make test notifications: email: