mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-02-03 13:14:28 +03:00
refactoring out common method to base class
This commit is contained in:
parent
80383aba19
commit
34d56787c4
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import unittest
|
import unittest
|
||||||
from os.path import exists, dirname, join
|
from os.path import exists, dirname, join
|
||||||
|
@ -14,6 +15,23 @@ class DjangoCookieTestCase(unittest.TestCase):
|
||||||
ctx = {}
|
ctx = {}
|
||||||
destpath = None
|
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):
|
def generate_project(self, extra_context=None):
|
||||||
ctx = {
|
ctx = {
|
||||||
"project_name": "My Test Project",
|
"project_name": "My Test Project",
|
||||||
|
|
|
@ -11,18 +11,7 @@ class TestCookiecutterSubstitution(DjangoCookieTestCase):
|
||||||
def test_all_cookiecutter_instances_are_substituted(self):
|
def test_all_cookiecutter_instances_are_substituted(self):
|
||||||
# Build a list containing absolute paths to the generated files
|
# Build a list containing absolute paths to the generated files
|
||||||
paths = self.generate_project()
|
paths = self.generate_project()
|
||||||
|
self.check_paths(paths)
|
||||||
# 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 test_flake8_complaince(self):
|
def test_flake8_complaince(self):
|
||||||
"""generated project should pass flake8"""
|
"""generated project should pass flake8"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user