cookiecutter-django/tests/test_cookiecutter_substitution.py

34 lines
1.0 KiB
Python
Raw Normal View History

2015-03-27 16:56:55 +03:00
import re
2015-04-20 15:19:12 +03:00
import sh
2015-03-27 16:56:55 +03:00
2015-04-20 15:19:12 +03:00
from .base import DjangoCookieTestCase
2015-03-27 16:56:55 +03:00
2015-04-20 15:19:12 +03:00
class TestCookiecutterSubstitution(DjangoCookieTestCase):
"""Test that all cookiecutter instances are substituted"""
2015-03-27 16:56:55 +03:00
def test_all_cookiecutter_instances_are_substituted(self):
# Build a list containing absolute paths to the generated files
2015-04-20 15:19:12 +03:00
paths = self.generate_project()
2015-03-27 16:56:55 +03:00
# 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))
2015-04-20 15:19:12 +03:00
def test_flake8_complaince(self):
"""generated project should pass flake8"""
self.generate_project()
try:
sh.flake8(self.destpath)
except sh.ErrorReturnCode as e:
raise AssertionError(e)