From 34d56787c466f6946bae533621952a9b75cb0de0 Mon Sep 17 00:00:00 2001 From: Burhan Khalid Date: Wed, 29 Jul 2015 00:11:06 +0300 Subject: [PATCH 1/2] refactoring out common method to base class --- tests/base.py | 18 ++++++++++++++++++ tests/test_cookiecutter_substitution.py | 13 +------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tests/base.py b/tests/base.py index f6ba90fb0..25e9daf7c 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1,4 +1,5 @@ import os +import re import shutil import unittest from os.path import exists, dirname, join @@ -14,6 +15,23 @@ class DjangoCookieTestCase(unittest.TestCase): ctx = {} destpath = None + def check_paths(self, paths): + """ + Method to check all paths have correct substitutions, + used by other tests cases + """ + # 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)) + def generate_project(self, extra_context=None): ctx = { "project_name": "My Test Project", diff --git a/tests/test_cookiecutter_substitution.py b/tests/test_cookiecutter_substitution.py index dd09daa80..4d62e26fe 100644 --- a/tests/test_cookiecutter_substitution.py +++ b/tests/test_cookiecutter_substitution.py @@ -11,18 +11,7 @@ class TestCookiecutterSubstitution(DjangoCookieTestCase): def test_all_cookiecutter_instances_are_substituted(self): # Build a list containing absolute paths to the generated files paths = self.generate_project() - - # 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)) + self.check_paths(paths) def test_flake8_complaince(self): """generated project should pass flake8""" From 9e3a92e3ee9f905b6decd2bdcce2561c4ec5faf8 Mon Sep 17 00:00:00 2001 From: Burhan Khalid Date: Wed, 29 Jul 2015 00:17:28 +0300 Subject: [PATCH 2/2] adding individual test methods, fixed typo. --- tests/test_cookiecutter_substitution.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_cookiecutter_substitution.py b/tests/test_cookiecutter_substitution.py index 4d62e26fe..5ac07406f 100644 --- a/tests/test_cookiecutter_substitution.py +++ b/tests/test_cookiecutter_substitution.py @@ -1,5 +1,4 @@ -import re - +from __future__ import absolute_import import sh from .base import DjangoCookieTestCase @@ -8,12 +7,24 @@ from .base import DjangoCookieTestCase class TestCookiecutterSubstitution(DjangoCookieTestCase): """Test that all cookiecutter instances are substituted""" - def test_all_cookiecutter_instances_are_substituted(self): + def test_default_configuration(self): # Build a list containing absolute paths to the generated files paths = self.generate_project() self.check_paths(paths) - def test_flake8_complaince(self): + def test_maildump_enabled(self): + paths = self.generate_project(extra_context={'use_maildump': 'y'}) + self.check_paths(paths) + + def test_celery_enabled(self): + paths = self.generate_project(extra_context={'use_celery': 'y'}) + self.check_paths(paths) + + def test_windows_enabled(self): + paths = self.generate_project(extra_context={'windows': 'y'}) + self.check_paths(paths) + + def test_flake8_compliance(self): """generated project should pass flake8""" self.generate_project() try: