mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-13 13:17:00 +03:00
Merge pull request #205 from kevgathuku/substitution-test
Implement basic test
This commit is contained in:
commit
20116f55bb
|
@ -3,8 +3,12 @@ language: python
|
||||||
before_install:
|
before_install:
|
||||||
- time pip install pep8
|
- time pip install pep8
|
||||||
|
|
||||||
|
install:
|
||||||
|
- pip install -r dev-requirements.txt
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- pep8 --ignore E201,E202 --max-line-length=120 --exclude='migrations' .
|
- pep8 --ignore E201,E202 --max-line-length=120 --exclude='migrations' .
|
||||||
|
- make test
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
|
|
3
dev-requirements.txt
Normal file
3
dev-requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
cookiecutter
|
||||||
|
pep8
|
||||||
|
pytest
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
41
tests/test_cookiecutter_substitution.py
Normal file
41
tests/test_cookiecutter_substitution.py
Normal file
|
@ -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()
|
Loading…
Reference in New Issue
Block a user